c# - DataList SelectedIndexChange event not firing -
i have hyperlink , hidden field inside datalist shown below
<asp:datalist id="clientslist" runat="server" onselectedindexchanged="clientslist_selectedindexchanged1" > <itemtemplate> <asp:hyperlink id="hlname" runat="server" text='<%# bind("name") %>' navigateurl="#" ></asp:hyperlink> <asp:hiddenfield id="hiddenfieldid" runat="server" value='<%# eval("id") %>' /> </itemtemplate> </asp:datalist>
when user clicks on hyperlink, need store value in application variable. selectedindexchange
event never fires.
this code:
protected void clientslist_selectedindexchanged1(object sender, eventargs e) { int idx = clientslist.selectedindex; hiddenfield hiddencid = clientslist.items[idx].findcontrol("hiddenfieldid") hiddenfield; if (hiddencid != null) { logger.updatelog("selected id: " + hiddencid.value.tostring()); } }
i binding data database datalist in page_load
event below , working fine.
protected void page_load(object sender, eventargs e) { if (!ispostback) { binddatalist(); } }
any idea why event never fired?
also code right far accessing hiddenfield
value concerned?
have set commandname property of hyperlink field?
<asp:linkbutton id="linkbutton1" runat="server" commandname="select">select</asp:linkbutton>
now in selectedindexchanged method:
protected void datalist1_selectedindexchanged(object sender, eventargs e) { int idx = datalist1.selectedindex; label lbl = (label)datalist1.items[idx].findcontrol("label1"); int id =convert.toint32(datalist1.selectedvalue); }
does work?
Comments
Post a Comment