asp.net - How to retrieve value by dynamically added checkbox -
here html code dynamically added checkbox
<asp:panel id="panel1" runat="server"> <asp:label id="label1" runat="server" text="text catogaries"></asp:label> <br /> <br /> <br /> <asp:repeater id="repeater1" runat="server"> <itemtemplate > <table> <td> <asp:checkbox id="checkbox1" runat="server" text='<%# eval("categoryname") %>'/> </td> </table> </itemtemplate> </asp:repeater> <br /> <asp:button id="button1" runat="server" text="button" onclick="button1_click" /> <br /> <br /> </asp:panel>
here code using behind button retrieve checkbox value
foreach (control cr in repeater1.controls) { // controls within repeater item foreach (control c in cr.controls) { checkbox chk = c checkbox; if (chk != null) { list.add(chk.text) } }
problem control not going in if condition adding value in list. how can add value in list.
use below code find checkbox repeater
foreach (repeateritem item in repeater1.items) { if (item.itemtype == listitemtype.item || item.itemtype == listitemtype.alternatingitem) { var checkbox1 = item.findcontrol("checkbox1") checkbox; if (checkbox1 != null) { // process further } } }
Comments
Post a Comment