This is a migrated thread and some comments may be shown as answers.

Programmatically enabling/disabling grid row editing

5 Answers 1300 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Mann
Top achievements
Rank 1
John Mann asked on 30 Dec 2008, 08:58 PM

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

Sort by
0
John Mann
Top achievements
Rank 1
answered on 30 Dec 2008, 11:22 PM

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;
}
}


0
Princy
Top achievements
Rank 2
answered on 31 Dec 2008, 06:38 AM
Hello John,

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.
0
John Mann
Top achievements
Rank 1
answered on 31 Dec 2008, 07:09 PM
Thank you. I'm using an ImageButton instead of a LinkButton, but your post helped me figure out how to substitute the standard icon for a grayed out version. Now I just need to fix it so the mouse cursor doesn't change when hovering over the disabled images.

John
0
Accepted
Princy
Top achievements
Rank 2
answered on 02 Jan 2009, 06:42 AM
Hello 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.
0
John Mann
Top achievements
Rank 1
answered on 12 Jan 2009, 10:39 PM
Thank you, just got back from vacation today, tried this and it worked like a charm. A good new technique to know.
Tags
Grid
Asked by
John Mann
Top achievements
Rank 1
Answers by
John Mann
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or