DataGrid EditCommand
-
Hi, I'm using .net 2008.i've a datagrid named 'dgUserNote'. I add edit,cancel,upadte and delete like this; and in coding part i written like; void dgUserNote_EditCommand(object source, DataGridCommandEventArgs e) { dgUserNote.EditItemIndex = e.Item.ItemIndex; } but when i click edit first time it will not work; second time only it will work likewise when i'm clicking cancel button first time it will not work,second time it is going to upadtecommand . cancel i written like this; void dgUserNote_CancelCommand(object source, DataGridCommandEventArgs e) { dgUserNote.EditItemIndex = -1; } and Update i written like this; SqlCommand SqlCom; try { if (ConGlobal.State == ConnectionState.Closed) ConGlobal.Open(); SqlCom = new SqlCommand("SpInsertUserNote", ConGlobal); SqlCom.Parameters.Add("@IorU", SqlDbType.VarChar).SqlValue = "U"; SqlCom.Parameters.Add("@Title", SqlDbType.VarChar).SqlValue = e.Item.Cells[2].Text; SqlCom.Parameters.Add("@Description", SqlDbType.VarChar).SqlValue = e.Item.Cells[3].Text; SqlCom.Parameters.Add("@Date", SqlDbType.VarChar).SqlValue = e.Item.Cells[4].Text; SqlCom.Parameters.Add("@UserName", SqlDbType.VarChar).SqlValue = mdlNewClass.gStrUserName; SqlCom.CommandType = CommandType.StoredProcedure; SqlCom.ExecuteNonQuery(); SqlCom = null; Response.Write("Record Updated Successfully..."); BindData(); dgUserNote.EditItemIndex = -1; } pls help me in this issue
-
Hi, I'm using .net 2008.i've a datagrid named 'dgUserNote'. I add edit,cancel,upadte and delete like this; and in coding part i written like; void dgUserNote_EditCommand(object source, DataGridCommandEventArgs e) { dgUserNote.EditItemIndex = e.Item.ItemIndex; } but when i click edit first time it will not work; second time only it will work likewise when i'm clicking cancel button first time it will not work,second time it is going to upadtecommand . cancel i written like this; void dgUserNote_CancelCommand(object source, DataGridCommandEventArgs e) { dgUserNote.EditItemIndex = -1; } and Update i written like this; SqlCommand SqlCom; try { if (ConGlobal.State == ConnectionState.Closed) ConGlobal.Open(); SqlCom = new SqlCommand("SpInsertUserNote", ConGlobal); SqlCom.Parameters.Add("@IorU", SqlDbType.VarChar).SqlValue = "U"; SqlCom.Parameters.Add("@Title", SqlDbType.VarChar).SqlValue = e.Item.Cells[2].Text; SqlCom.Parameters.Add("@Description", SqlDbType.VarChar).SqlValue = e.Item.Cells[3].Text; SqlCom.Parameters.Add("@Date", SqlDbType.VarChar).SqlValue = e.Item.Cells[4].Text; SqlCom.Parameters.Add("@UserName", SqlDbType.VarChar).SqlValue = mdlNewClass.gStrUserName; SqlCom.CommandType = CommandType.StoredProcedure; SqlCom.ExecuteNonQuery(); SqlCom = null; Response.Write("Record Updated Successfully..."); BindData(); dgUserNote.EditItemIndex = -1; } pls help me in this issue
Maybe i'm missing something but my guess is you should rebind your DataGrid after the event fires. Example with your Edit Handler
protected void dgUserNote_EditCommand(object source, DataGridCommandEventArgs e)
{
dgUserNote.EditItemIndex = e.Item.ItemIndex;
BindData();
}If you Re-Bind your DataGrid after all your commands are issued it should work fine for you. Best of luck,
Cheers Disgyza Programmer Analyst
-
Maybe i'm missing something but my guess is you should rebind your DataGrid after the event fires. Example with your Edit Handler
protected void dgUserNote_EditCommand(object source, DataGridCommandEventArgs e)
{
dgUserNote.EditItemIndex = e.Item.ItemIndex;
BindData();
}If you Re-Bind your DataGrid after all your commands are issued it should work fine for you. Best of luck,
Cheers Disgyza Programmer Analyst
Thanks for the solution. can u pls help me to find solution regarding with my Datagrid. I'm new to c#. in my coding i'm using control DataGrid named dgUserNote. in its update command , i'm not getting the values in the cells when i take e.Item.Cells[2].Text it shows like; e.Item.Cells[2].Text="" the code is as follows; in designing part(asp) i add the Column as follows; UpdateText="Update"> in coding (c#) i wrote like this; void dgUserNote_UpdateCommand(object source, DataGridCommandEventArgs e) { SqlCommand SqlCom; if (ConGlobal.State == ConnectionState.Closed) ConGlobal.Open(); SqlCom = new SqlCommand("SpInsertUserNote", ConGlobal); SqlCom.Parameters.Add("@IorU", SqlDbType.VarChar).SqlValue = "U"; SqlCom.Parameters.Add("@Title", SqlDbType.VarChar).SqlValue = e.Item.Cells[2].Text; SqlCom.Parameters.Add("@Description", SqlDbType.VarChar).SqlValue = e.Item.Cells[3].Text; SqlCom.Parameters.Add("@Date", SqlDbType.VarChar).SqlValue = e.Item.Cells[4].Text; SqlCom.Parameters.Add("@UserName", SqlDbType.VarChar).SqlValue = mdlNewClass.gStrUserName; SqlCom.CommandType = CommandType.StoredProcedure; SqlCom.ExecuteNonQuery(); SqlCom = null; Response.Write("Record Updated Successfully..."); BindData(); dgUserNote.EditItemIndex = -1; dgUserNote.DataBind(); } pls help me to solve this problem Thanks&Regards Princy