Please tell me the "GENERAL CODING" for all the operations( insertion, deletion, edition(updation, cancel), selection, paging, sorting) that can be performed on gridview (programmitically not by declarative).
what i have tried is as below"
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex]["id"].ToString();
TextBox tx1 = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[1];
TextBox tx2 = (TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[1];
CheckBox cb = (CheckBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[1];
string qu = "update emp set Name='" + tx1.Text + "',City='" + tx2.Text + "',IsTemp ='"+ cb.Checked +"' where id=" + id + "";
int i = obj.ExecuteQuery(qu);
GridView1.EditIndex = -1;
if (i > 0)
{
Bind();
}
}
Supppose i have written the code for rest operations in the similar manner, so as i have used Cells[2].Controls[1]; whenver i add or delete any column, i have to rewrite the code, therefore i need the "GENERAL CODING" for all the operations( insertion, deletion, edition(updation, cancel), selection, paging, sorting) that can be performed on gridview.
what i have tried is as below"
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex]["id"].ToString();
TextBox tx1 = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[1];
TextBox tx2 = (TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[1];
CheckBox cb = (CheckBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[1];
string qu = "update emp set Name='" + tx1.Text + "',City='" + tx2.Text + "',IsTemp ='"+ cb.Checked +"' where id=" + id + "";
int i = obj.ExecuteQuery(qu);
GridView1.EditIndex = -1;
if (i > 0)
{
Bind();
}
}
Supppose i have written the code for rest operations in the similar manner, so as i have used Cells[2].Controls[1]; whenver i add or delete any column, i have to rewrite the code, therefore i need the "GENERAL CODING" for all the operations( insertion, deletion, edition(updation, cancel), selection, paging, sorting) that can be performed on gridview.