Reputation: 219
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?
Upvotes: 2
Views: 1650
Reputation: 11433
I think you meant to use the .value property, as in HiddenField1.Value
:
t1 = (TextBox)GridView1.Rows[int.Parse(HiddenField1.Value)].Cells[3].Controls[0];
It looks like, before, you were trying to convert a HiddenField
control into an int
, which isn't going to work. Also, you can just use int.Parse
to convert the value stored in the HiddenField
into an int
.
Upvotes: 1