saifullah khan

saifullah khan

  • NA
  • 335
  • 301.1k

Object reference not set to an instance of an object.

May 28 2011 8:05 AM
i want to edit and update data in grid view but i get he following error.
Object reference not set to an instance of an object.
Line 74:         DTSample.Rows[e.RowIndex]["Column0"] = t1.Text;

the code the given below. please help me
 
 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = Convert.ToInt32(e.NewEditIndex);
        HiddenField1.Value = e.NewEditIndex.ToString();
        GridView1.DataBind();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        TextBox t1 = new TextBox();
        TextBox t2 = new TextBox();
        t1 = (TextBox)GridView1.Rows[Convert.ToInt32(HiddenField1.Value)].Cells[2].Controls[0];
        t2 = (TextBox)GridView1.Rows[Convert.ToInt32(HiddenField1.Value)].Cells[3].Controls[0];
        DTSample.Rows[e.RowIndex]["roll"] = t1.Text;
        DTSample.Rows[e.RowIndex]["name"] = t2.Text;
        GridView1.EditIndex = -1;
        GridView1.DataBind();

 
    }

Answers (4)