i have one Gridview (Gridview1) i want to make this Grid editable. For this i have set :
RowEditing = TRUE
RowUpdating = TRUE
After this i have got Edit/Delete button on the extreme Left of the Gridview followed by my Autogenerated columns from the database(Column0 , Column1 ,Column2).
I have written following code in Code Behind :
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
Fillgrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
for(i=0 ; i < GridView1.Rows.Count-1 ; i ++)
{
SqlCommand cmd_update = new SqlCommand(" update myproducts set name = '" + GridView1.Rows[i].Cells[2].Text + "' where id='" + GridView1.Rows[i].Cells[1] + "'");
}
GridView1.EditIndex = -1;
Fillgrid();
}
}
public void Fillgrid()
{
SqlDataReader reader = null;
SqlCommand command = new SqlCommand("Select * from myproducts",con);
con.Open();
reader = command.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataSource = reader;
GridView1.DataBind();
}
When i click on the Edit label text , my row becomes editable , however when i click on update...nuthing happens..i mean the values do not get updated.
I even inserted a breakpoint on : protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
to check what happens on the click of Update however i was surprised to c that this event is actually not called n hence is not executed !!
Where am i goin wrong....plz suggest....improvement in the above code shall b appreciated.
cya
Rohan