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

Row selecting

4 Answers 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chad Johnson
Top achievements
Rank 1
Chad Johnson asked on 16 Oct 2008, 06:43 PM
Greetings,

Is it possible to allow only certain rows within a grid to be selectable?  Here is the scenario:  you have a set of users, say 20.  They have a grid that logs comments, which has the ability to add and edit comments (it's EditMode is PopUp).  There is a set of users, primarily webmasters, who can edit anyone's comment, while everyone else can only edit their own comments.  To edit, you must select a record and hit the edit button.  What I want to do is to stop a user from being able to select that record either by stopping them in javascript or not allowing the row to be selectable at all.  Thanks.

Chad

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Oct 2008, 05:09 AM
Hello Chad,

To prevent a particular user from not editing other rows you can try out the following code.
aspx:
 <telerik:GridBoundColumn DataField="User" UniqueName="User" HeaderText="Users"
     </telerik:GridBoundColumn> 

cs:
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            string strtxt1 = dataItem["User"].Text; 
            if (strtxt1 != "John") 
            { 
                dataItem.Edit = false;          
            }            
        } 
    } 

Thanks
Princy.
0
Chad Johnson
Top achievements
Rank 1
answered on 17 Oct 2008, 11:04 AM
Thank you for your reply, but this only turned the Edit on permanetly on the page, thus not allowing users to choose at all.  Is there another way possibly?
0
Vlad
Telerik team
answered on 17 Oct 2008, 11:09 AM
Hello Chad,

You can stop the selection if you execute args.set_cancel(true) in the client-side OnRowSelecting event handler:

function RowSelecting(sender, args)
{
    if(your condition)
    {
       args.set_cancel(true);
    }
}

Best wishes,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Morten
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 23 Mar 2014, 08:14 PM
this works for me:

GridDataItem gdi;
switch (e.Item.ItemType) {
...
...
case GridItemType.EditItem:
gdi = (GridDataItem)e.Item;
gdi.SelectableMode = GridItemSelectableMode.None;
Tags
Grid
Asked by
Chad Johnson
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Chad Johnson
Top achievements
Rank 1
Vlad
Telerik team
Morten
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or