I wanted to update my table through gridview. [Visual Studio 2010]
For that i have done following:
Gridview>> EditColumns >> CommandField >> Edit,update,cancel Added to grid.
Gridview>> EditTemplates >> Added textbox names "TextBox1
">>End Editing Template.
Row Editing Event:
public int i;
protected void gv_RowEditing(object sender, GridViewEditEventArgs e)
{
i=gv.EditIndex = e.NewEditIndex;
}
Row Updating Event:
protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
TextBox txtSymbol;
txtSymbol = ((TextBox)(gv.Rows[e.RowIndex].Cells[3].FindControl("TextBox1")));
con.Open();
cmd = new SqlCommand("update temp set Symbol=@Symbol", con);
cmd.Parameters.AddwithValue("@Symbol",txtSymbol.Text);
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
}
}
I refered this code from here.
Here its mentioned that th line should be like this:
txtSymbol = ((TextBox)(gv.Rows[e.RowIndex].Cells[3].FindControl("TextBox1")));
All this coded thing is not working.
`((TextBox)(gv.Rows[e.RowIndex].Cells[3].FindControl("TextBox1")))`
is having null value.
Gives exception in Row Updating event as "Null Referance Exception."
What is wrong in my code?
Where i am making mistake.
Please guid me.