Hi all, I need your help.
I can't get the value of the hidden field that I predicted in my gridview.
I have this error
Server Error in '/aspnet' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 882:
Line 883: HiddenField empID = (HiddenField)FindControl("HiddenField1");
Line 884: string empID2 = empID.Value;
Line 885: Response.Write(empID.ToString()); Response.End();
Line 886:
My code below
<asp:Panel ID="pngv" runat="server" HorizontalAlign="Left">
<fieldset>
<asp:GridView ID="gvProducts"
runat="server"
DataKeyNames="sID"
EmptyDataText="Nessun dato disponibile"
EnableViewState="true"
CssClass="mGrid"
HorizontalAlign="Center"
OnRowDataBound="gvProducts_RowDataBound"
AutoGenerateColumns="false"
Width="100%">
<AlternatingRowStyle CssClass="altrows" />
<Columns>
<asp:TemplateField
HeaderText="N."
ItemStyle-CssClass="ddl_Class_new"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%#String.Format("{0:N0}",Container.DataItemIndex + 1)%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Code"
HeaderText="Code"
ReadOnly="true" HtmlEncode="false"
ItemStyle-CssClass="ddl_Class_new"
ItemStyle-HorizontalAlign="Center"
DataFormatString="{0:N0}" />
</asp:GridView>
</fieldset>
<asp:HiddenField ID="HiddenField1" runat="server" Value="1" />
</asp:Panel>
<asp:ImageButton ID="btn"
ImageUrl="/aspnet/img/validate_button.gif"
runat="server"
OnClick="btn_Click"
CssClass="ddl_Class_new"
Visible="true" />
protected void btn_Click(object sender, ImageClickEventArgs e)
{
ImageButton imgbtn = (ImageButton)sender;
HiddenField empID = (HiddenField)FindControl("HiddenField1");
string empID2 = empID.Value;
Response.Write(empID.ToString());
}