Retrieving DataGrid Cell value
<p>I Have just started learning ASP.Net. Last night i was working on Grid View in which i fill data by directly giving command to database. I haven't defined any template field for my grid and i have set AutoGenerated edit button to true. Data is getting displayed corrrectly but While trying to handle update event i'm facing problem as i'm unable to retrieve cell value for the row i'm updating. </p>

<p>I googled a lot but all the examples for retrieving cell value are based on template field but in my case i'm not defining the columns of the grid at design time.
Please help me.</p>

<p>My Code is below: (GridView1_RowUpdating method is giving empty value when i checked by applying break point)</p>

<pre><code>  private void FillGrid()
        {
            SqlConnection con = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=TestDatabase;Integrated security=true;");
            DataTable dt = new DataTable("Student");
            using (SqlDataAdapter adapter = new SqlDataAdapter("select name,age,Fathername,dob from student", con))
            {
                adapter.Fill(dt);
            }
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            FillGrid();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //Response.Write("RowDataBoundEvent Occured"+" "+e.Row.RowType+"\n");
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            FillGrid();
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            FillGrid();
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

            string name = GridView1.Rows[e.RowIndex].Cells[2].Text;
            string age = GridView1.Rows[GridView1.EditIndex].Cells[3].Text;
            string salary = GridView1.Rows[GridView1.EditIndex].Cells[4].Text;
        }
</code></pre>
