AvinashKN
asked on
Disabling delete button while editing Gridview
Hello all,
I would like to know if its possible to disable the delete button while the user is editing a row in a gridview. I've posted the code I was experiementing with but it obviously is not the right solution since it only disables the first row.
I would like to know if its possible to disable the delete button while the user is editing a row in a gridview. I've posted the code I was experiementing with but it obviously is not the right solution since it only disables the first row.
Button btn = (Button)dgUserLevel.Rows[0].FindControl("btnDelete");
btn.Enabled = false;
Hello AvinashKN,
Because that is what you have told it to do: (Button)dgUserLevel.Rows[0 ] <- First row.
Depending on what event you are using this in you have various properties such as e.RowIndex or dgUserLevel.EditIndex which will allow you to specify the current row.
Regards,
TimCottee
Because that is what you have told it to do: (Button)dgUserLevel.Rows[0
Depending on what event you are using this in you have various properties such as e.RowIndex or dgUserLevel.EditIndex which will allow you to specify the current row.
Regards,
TimCottee
ASKER
How do I specify the current row?
The SelectedRows property contains a collection of the currently selected rows. Since the user is editing, this will be one row. So, the following row is the current row:
dbUserLevel.Rows[0]
This should always work. Could you try this please?
dbUserLevel.Rows[0]
This should always work. Could you try this please?
ASKER
I cannot specify rowindex either for whatever reason.
protected void dgUserLevel_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
dgUserLevel.EditIndex = e.NewEditIndex;
PopulateUserLevelDataGrid();
Button btn = (Button) dgUserLevel.Rows[0].FindControl("btnDelete");
btn.Enabled = false
AvinashKN,
Try this:
TimCottee
Try this:
TimCottee
protected void dgUserLevel_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
dgUserLevel.EditIndex = e.NewEditIndex;
PopulateUserLevelDataGrid();
GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
Button btn = (Button) row.FindControl("btnDelete");
btn.Enabled = false
ASKER
Thanks for the help.
TimCottee:
I'm getting the following error.
'System.Web.UI.WebControls .GridViewE ditEventAr gs' does not contain a definition for 'CommandSource'
pvginkel:
I'm getting the following error:
Cannot apply indexing with [] to an expression of type 'System.Web.UI.WebControls .GridViewR ow'
TimCottee:
I'm getting the following error.
'System.Web.UI.WebControls
pvginkel:
I'm getting the following error:
Cannot apply indexing with [] to an expression of type 'System.Web.UI.WebControls
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help pvginkel. It works.
I would also like to thank Tim Cotee. Since I'm a complete newbie to asp.net programming, his explanation was very helpful.
Thank you both.
I would also like to thank Tim Cotee. Since I'm a complete newbie to asp.net programming, his explanation was very helpful.
Thank you both.
Open in new window