Link to home
Start Free TrialLog in
Avatar of VD1234
VD1234

asked on

Hidden field in a datagrid

I have a hidden field in a datagrid defined as follows:
<asp:TemplateColumn HeaderText="Index Field Names" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label id="lblFieldName" runat="server" >
<input type="hidden" ID="hdnID" value='<%# DataBinder.Eval(Container, "DataItem.DocMapId") %>' runat="server" NAME="hdnID"/></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>

Then in the backend, I try to access this hidden field as follows:
foreach (DataGridItem dgItem in dgdMapping.Items)
 {
                       HtmlInputHidden hdnID = dgItem.Cells[0].FindControl("hdnID") as HtmlInputHidden;
                      int intID = Convert.ToInt32(hdnID.Value);
}

But hdnID is assigned null. IT does not find the right control at right time.

How do I access the hidden value at run time through the datagrid.

Please help. Thanks in advance!


                 
ASKER CERTIFIED SOLUTION
Avatar of Sammy
Sammy
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VD1234
VD1234

ASKER

Yeah, I am catching the hidden control in the item databound event. Is it impossible to access it in a method other than the events as follows?
HtmlInputHidden hdnID = dgItem.Cells[0].FindControl("hdnID") as HtmlInputHidden;

Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
Community Support Moderator