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

GridClientSelectColumn : Make row selected from code-behind according to values from database

1 Answer 46 Views
Grid
This is a migrated thread and some comments may be shown as answers.
PPRINC
Top achievements
Rank 1
PPRINC asked on 18 May 2014, 02:42 PM
       
Hello, I want to make some rows selected from code-behind according to values from database
 
Client Side  
 <telerik:RadGrid ID="Grid" runat="server" AllowPaging="True" 
                          PageSize="5"     Width="100%"    OnPageIndexChanged="GridCourse_PageIndexChanged"
                          OnPreRender="Grid_PreRender"
                            GridLines="None" Skin="Vista" AllowMultiRowSelection="True" >
                            <MasterTableView DataKeyNames="CHOOSE"   >
                            <Columns>
                                <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn"  ></telerik:GridClientSelectColumn>                               
                             </Columns>
                            </MasterTableView>
                             
                            <ClientSettings EnableRowHoverStyle="true"  >
                                <Selecting AllowRowSelect="True"  />
                            </ClientSettings>
                        </telerik:RadGrid>    

Code-behind
Here is what I'm doing with no success....
protected void Grid_PreRender(object sender, EventArgs e)
        {
                 if (!IsPostBack)
                {
                    foreach (GridDataItem item in GridCourse.MasterTableView.Items)
                    {
                        if (item.GetDataKeyValue("CHOOSE").ToString().ToUpper() == "Yes".ToUpper())
                        {
                            item.Selected = true;
                        }
                    }
                }
      
        } 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 19 May 2014, 02:57 AM
Hi,

I guess you want to keep some rows selected always, please try the following code snippet.

C#:
protected void Grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
  {
    GridDataItem dataItem = (GridDataItem)e.Item;
    if (dataItem.GetDataKeyValue("CHOOSE").ToString().ToUpper() == "Yes".ToUpper())     
    {
      dataItem.Selected = true;
    }
  }
}

Thanks,
Princy
Tags
Grid
Asked by
PPRINC
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or