I am trying to perform an update action in GRID VIEW control in asp.net.
My code:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox t1 = new TextBox();
t1 = (TextBox)GridView1.Rows[Convert.ToInt16(HiddenField1)].Cells[3].Controls[0];
}
When I run, I get the error as “Unable to cast object of type ‘System.Web.UI.WebControls.HiddenField’ to type ‘System.IConvertible”
Can anyone help me in suggesting a solution for this?
I think you meant to use the .value property, as in
HiddenField1.Value:It looks like, before, you were trying to convert a
HiddenFieldcontrol into anint, which isn’t going to work. Also, you can just useint.Parseto convert the value stored in theHiddenFieldinto anint.