Hello,
I would like to enable or disable editing in any given row in a radgrid based upon data values in that same row. I've tried using both ItemCreated and ItemDataBound and am able to see the values for each row in the grid, but I haven't been able to figure out how to access the cell that contains theGridEditCommandColumn and turn it on or off. I've managed to turn the editor on and off for the entire column, but not for individual rows. Also, rather than just not displaying the edit icon, it would be nice to just disable it so it appears grayed out.
Thank you for your help. I'm very new to asp.net and Telerik, but am slowly finding my around.
John
5 Answers, 1 is accepted
I figured out most of this. The following code will check the status of check box gcbApproved. If checked, both the edit and delete buttons will be disabled. They appear unchanged however and the mouse cursor turns into the hand when hovering over them, but at least clicking them has no effect. This is in the ItemDataBound event.
if (e.Item is GridDataItem)
{GridDataItem dataItem = (GridDataItem)e.Item;
if (((CheckBox)(dataItem["gcbApproved"].Controls[0])).Checked == true)
{
dataItem["gecEditControls"].Enabled = false;
dataItem["btnDelete"].Enabled = false;
}
}
The code you have used should work if you want to disable the entire cell which contains the Edit/Delete buttons. I'm not sure of what might be wrong at your end. Make sure that the UniqueNames of the columns are the same as that mentioned in the code.
I tried the following at my end and it works as expected:
aspx:
<telerik:GridCheckBoxColumn DataField="Condition" UniqueName="Condition" HeaderText="Condition"></telerik:GridCheckBoxColumn> |
<telerik:GridEditCommandColumn HeaderText="Edit" UniqueName="Edit" ></telerik:GridEditCommandColumn> |
cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridDataItem) |
{ |
GridDataItem dataItem = (GridDataItem)e.Item; |
if (((CheckBox)(dataItem["Condition"].Controls[0])).Checked == true) |
{ |
dataItem["Edit"].Enabled = false;// to disable the entire cell |
((LinkButton)dataItem["Edit"].Controls[0]).Enabled = false;// to disable the edit button |
} |
} |
} |
Thanks
Princy.
John
You can try the following code to set the cursor style on hovering over the imagebutton or cell:
cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridDataItem) |
{ |
GridDataItem dataItem = (GridDataItem)e.Item; |
((ImageButton)dataItem["Edit"].Controls[0]).Enabled = false; |
((ImageButton)dataItem["Edit"].Controls[0]).Attributes.Add("style", "cursor:pointer"); |
dataItem["Edit"].Attributes.Add("style", "cursor:pointer");// for the entire cell. |
} |
} |
Happy New Year!!
Princy.