How to set Item index in a Repeater Column with Hidden Fields in asp.net.
I wrote the following code but it does not show the 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 anything necessarily wrong with the itemtemplate, it would probably help if you provide the entire repeater code as a direct copy / paste in case there area any other errors.
Another approach you can take is to add a repeater data item bound event and then capture the hiddenfield in the event. Once you have the hidden input you can simply set it’s value.
Repeater code:
And the code behind event: