Hi Kuldeep,
With these lines of code u would be able to do it....
private void datagrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
datagrid1.EditItemIndex = e.Item.ItemIndex;
datagrid1.DataBind();
}
private void datagrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
SqlCommandBuilder cb=new SqlCommandBuilder(DataAdapterObject);
// Delete Corresponding row
ds.Tables [0].Rows [e.Item.DataSetIndex].Delete();
DataAdapterObject.Update (ds);
Page.DataBind ();
}
private void datagrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
datagrid1.EditItemIndex = -1;
datagrid1.DataBind();
}
private void datagrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
TableCell tc = e.Item.Cells[2];
string s = ((TextBox)tc.Controls[0]).Text;
ds.Tables[0].Rows[e.Item.DataSetIndex]["Role"] = s;
SqlCommandBuilder scb = new SqlCommandBuilder(DataAdapterObject);
DataAdapterObject.Update(ds);
// Edit operation should be cancelled
datagrid1.EditItemIndex = -1;
datagrid1.DataBind();
}
But i think your problem is different because that much u can get in help document also. So reply it u need something different.
Pooja Shukla
Hi all
I want to know that how to edit,Delete and cancel data in datagrid using c#. Any body would like to help me plz for this.
kuldeep singh sethi