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

[Solved] [RadGrid] Allow the edition of only some lines

2 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christophe
Top achievements
Rank 1
Christophe asked on 20 May 2008, 08:46 AM
Hello,

I used a RadGrid to add/update my data.
My grid is linked to an ObjectDataSource that provides me some methods for select, insert, update, delete.
The actions on the grid are available by a GridEditCommandColumn for editing and a GridButtonColumn for deleting.
My problem is about to allow the edition of only some lines of my grid (depending to business rules that I can define in the SelectMethod).
Is there a mean to hide the Edit Button depending on this data (like I can for example enable a RadComboBox in an EditItemTemplate by this way : 
Enabled='<%# Eval("Enabled") %>') ?
I think use one of the following ways, but my attempts are not really good :
- use a GridButtonColumn, but that means that I must manage myself the behavior of this links in this column in edit mode (UpdateText, CancelText, ...)
- Use HTML (or Javascript ?) in the EditText of my GridEditCommandColumn to specify on the client side the Edit text to display (or not display in my case) depending on the "Editable" field returned by my SelectMethod.
Is it a good way to reach my goal ? Have you others ideas to solve my problem ?

Thank you in advance,

Christophe.

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 20 May 2008, 09:33 AM
Hi Christophe,

Try the following code snippet to hide the Edit button .

CS:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
     { 
         if (e.Item is GridDataItem) 
         { 
             GridDataItem item = (GridDataItem)e.Item; 
             LinkButton lnkbtn = (LinkButton)item["Edit"].Controls[0]; 
             string strKey = item["columnUniqueName"].Text.ToString(); 
             if (strKey == "Cola") 
             { 
                 lnkbtn.Visible = false
             } 
              
         } 
   } 

Thanks
Shinu.
0
Christophe
Top achievements
Rank 1
answered on 20 May 2008, 10:24 AM
Thanks Shinu, it works fine !
I used ItemDataBound with GridView but I don't think to use this event with RadGrid...
Tags
Grid
Asked by
Christophe
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Christophe
Top achievements
Rank 1
Share this question
or