Problem with GridClientSelectColumn

3 posts, 0 answers
  1. Thomas
    Thomas avatar
    143 posts
    Member since:
    Feb 2007

    Posted 29 Jan 2008 Link to this post

    I have a grid with a GridClientSelectColumn column like so:

     <telerik:RadGrid ID="Foo" runat="server"  
                        Width="275px" Height="400px"  
                        AllowAutomaticDeletes="false" AllowAutomaticInserts="false" AllowAutomaticUpdates="false"  
                        AutoGenerateColumns="false" ShowHeader="true" ShowFooter="false" 
                        OnPreRender="Foo_PreRender" > 
                        <MasterTableView DataKeyNames="Key" ShowHeadersWhenNoRecords="true" TableLayout="fixed"
                                    <ItemStyle Width="30px" /> 
                                    <HeaderStyle Width="30px" /> 
                                <telerik:GridBoundColumn DataField="Description" HeaderText="Display Choice" UniqueName="Description"
                                    <ItemStyle Width="220px" /> 
                                    <HeaderStyle Width="220px" /> 
                        <ClientSettings ApplyStylesOnClient="true" > 
                            <Selecting AllowRowSelect="true" EnableDragToSelectRows="true"  /> 
                            <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="300px" /> 

    This grid is on a UserControl which is on a Page with a Master Page set and the UserControl is loaded at runtime. When the user navigates to the page, they can use the various built-in selection techniques to select multiple items and then hit a button which stores the selections into session. All that works peachy.

    The problem comes when they navigate back to this page with the grid and I try to selected the items they previously selected. I have tried setting the selected items from the Page_Load and from the grid's PreRender like so:

     foreach ( MyCustomDisplayItem displayItem in this.CurrentSelections ) 
                    foreach ( GridItem item in this.Foo.MasterTableView.Items ) 
                        GridDataItem dataItem = item as GridDataItem; 
                        if ( dataItem == null ) 
                        string key = dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["Key"].ToString(); 
                        if ( string.CompareOrdinal( key, displayItem.Key ) != 0 ) 
                        dataItem.Selected = true

    In this case, "this.CurrentSelections" is a collection of MyCustomDisplayItem objects. When the page renders on a return navigation, the checkboxes on the GridClientSelectColumn are in fact checked. However, if the user checks a few unchecked items and then posts the results, the codebehind only sees the new checked items.

    For example, suppose there are 10 items in the list and on the first pass, the user selects five of them. They post the results and then come back whereby they select two more items. When they post the second time, the SelectedItems property only contains the two items they checked. It does not see the original five. In addition, while the GridClientSelectColumn is checked for the items where I set Selected to true, the row is does not appear selected as it would if the the user were to select it.

    My goal is simple: I want to populate the grid on return such that it looks exactly as it did when they first selected items.

  2. Rosen
    Rosen avatar
    3247 posts

    Posted 01 Feb 2008 Link to this post

    Hi Thomas,

    In order to achieve the requested functionality you should set items to selected after they are created and databound. Therefore page's load and init event are to early for this as RadGrid is bound after that and selection is overridden. More appropriate place will be in ItemDataBound event. I have attached a simple page that demonstrates how to implement this behavior.

    Kind regards,
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Thomas
    Thomas avatar
    143 posts
    Member since:
    Feb 2007

    Posted 01 Feb 2008 Link to this post

    Excellent! That did the trick.
Back to Top