.net - use Repeater Item index in Hidden Field -
how set item index in repeater column hidden fields in asp.net.
wrote following code not show index value in hidden field.
<itemtemplate> <tr> <td> <asp:hiddenfield id="hiddenfield1" runat="server" value='<%# container.itemindex+1 %>' /> <%--<asp:hiddenfield id="hfindex" runat="server" value='<%#container.itemindex+1 %>' />--%> </td> <td> <asp:label id="lblexpenseglcode" runat="server" text='<%# databinder.eval(container.dataitem, "acm_account_code")%>'></asp:label> </td> <td> <asp:label id="lblaccountgldescription" runat="server" text='<%# databinder.eval(container.dataitem, "acm_account_desc")%>'></asp:label> </td> </tr> </itemtemplate>
i can't see wrong itemtemplate, if provide entire repeater code direct copy / paste in case there area other errors.
another approach can take add repeater data item bound event , capture hiddenfield in event. once have hidden input can set it's value.
repeater code:
<asp:repeater id='myrepeater' runat="server" onitemdatabound='myrepeater_onitemdatabound'> <itemtemplate> <asp:hiddenfield id='myhidden' runat="server" /> </itemtemplate> </asp:repeater>
and code behind event:
protected void myrepeater_onitemdatabound(object sender, repeateritemeventargs e) { if (e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem) { var myhidden = (hiddenfield)e.item.findcontrol("myhidden"); myhidden.value = e.item.itemindex.tostring(); } }
Comments
Post a Comment