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

[Solved] Radgrid selection of a row possible determined by an if statement

1 Answer 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Larevenge
Top achievements
Rank 1
Larevenge asked on 23 Jul 2009, 09:32 PM
Hello,

I have a problem with the radgrid selection option. I can't find anything related to what i want or better said i dont know on what i have to search for. I want to fill a radgrid with a list of items from the database. One of the columns says if the row is obligated or not.

What i want to build in my RadGrid, is the possibility to select the rows, but when the row is obligated it is already selected and it cannot be undone by the user. This to make sure i get the full list of items back into another table in the database.

Anyone knows what i have to search for?

Thanks a lot in advance.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Jul 2009, 06:09 AM
Hello,

I hope you are successfully populated the grid and want to set selection based on column value. If so one suggestion would be selecting the row in client side OnRowCreated event (after checking the obligated value) and cancel the deselection if the value is obligated. Here is the code that I tried.

ASPX:
 
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" AllowMultiRowSelection="true" DataSourceID="SqlDataSource1"
    <MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource1" ClientDataKeyNames="CustomerID"
       . . .             
    </MasterTableView> 
    <ClientSettings> 
        <Selecting AllowRowSelect="true" /> 
        <ClientEvents  OnRowDeselecting="OnRowDeselecting" OnRowCreated="OnRowCreated" /> 
    </ClientSettings> 
</telerik:RadGrid> 

JavaScript:
 
<script type="text/javascript"
function OnRowCreated(sender, eventArgs) 
    if(eventArgs.getDataKeyValue("Obligated") == 'Yes'// Check for condition 
    { 
        eventArgs.get_gridDataItem().set_selected(true);     
    }     
function OnRowDeselecting(sender, eventArgs) 
    if(eventArgs.getDataKeyValue("Obligated") == 'Yes'// Check for condition 
    { 
        eventArgs.set_cancel(true//cancel event;     
    }     
</script> 

Shinu.
Tags
Grid
Asked by
Larevenge
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or