Im pretty new to the object oriented realm and Im a little puzzled how to declare a gridview control and set it to an instance of an object. Im having trouble with the null reference exception error and thats because it is not referenced correctly.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
var MyLabel = (Label) GridView1.FindControl("lblTest");
cmd.Parameters.Add("@X", SqlDbType.Char).Value = MyLabel.Text;
}
lblTest is the name of the label control in the gridview. But I need to declare this globally and I am not too sure how. If someone could point me to the right direction and help me with the syntax it would be greatly appreciated!
If you do have gridview control on the aspx page with lblTest in it then you need to find control on a particular row. In GridView1_RowUpdating do:
Here you could do:
Var is used for implicit typed variable. You can find this link interesting for var