ok first of all make a function from which u will populate your gridview like this :
public void show()
{
string str = "select * from table2";
SqlDataAdapter adp = new SqlDataAdapter(str, con);
DataSet ds = new DataSet();
adp.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
then go to your gridview and click on the smart tag from there select uption edit columns and add a new command feild "edit, update and cancel"
now go to gridview events
double click the RowEditing event:
gridShow.EditIndex = e.NewEditIndex;
show();
similarly,
under RowCancelling event:
GridView1.EditIndex = -1;
show();
under RowUpdating event:
before doing that you should know that you should convert your gridview columns into only template fields go to smart tag of gridview and click edit template and then for the columns you dont want to edit insert a label in their edititemtemplate and the fields you want to change add a textbox
int id =Convert.ToInt32( ((Label)GridView1.Rows[e.RowIndex].FindControl("Label4")).Text);
string userid = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2")).Text;
string pwd = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3")).Text;
string str = "update table2 set userid='" + userid + "',pwd='" + pwd + "' where id=" + id;
SqlCommand cmd = new SqlCommand(str, con);
cmd.Connection = con;
cmd.ExecuteNonQuery();
cmd.Dispose();
GridView1.EditIndex = -1;
show();
delete is done like this:
int id = Convert.ToInt32(((Label)GridView1.Rows[e.RowIndex].FindControl("Label12")).Text);
string del = "Delete from monthly where id="+id;
SqlCommand cmd = new SqlCommand(del, con);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
cmd.Dispose();
show();
just tweak the code and it will work for you.