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

Problem with GridClientSelectColumn

2 Answers 277 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 30 Jan 2008, 01:29 AM
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"  
                    AllowMultiRowSelection="true"  
                    AutoGenerateColumns="false" ShowHeader="true" ShowFooter="false" 
                    OnPreRender="Foo_PreRender" > 
                    <MasterTableView DataKeyNames="Key" ShowHeadersWhenNoRecords="true" TableLayout="fixed"
                        <Columns> 
                            <telerik:GridClientSelectColumn> 
                                <ItemStyle Width="30px" /> 
                                <HeaderStyle Width="30px" /> 
                            </telerik:GridClientSelectColumn> 
                            <telerik:GridBoundColumn DataField="Description" HeaderText="Display Choice" UniqueName="Description"
                                <ItemStyle Width="220px" /> 
                                <HeaderStyle Width="220px" /> 
                            </telerik:GridBoundColumn> 
                        </Columns> 
                    </MasterTableView> 
                    <ClientSettings ApplyStylesOnClient="true" > 
                        <Selecting AllowRowSelect="true" EnableDragToSelectRows="true"  /> 
                        <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="300px" /> 
                    </ClientSettings> 
                </telerik:RadGrid> 

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 ) 
                        continue
 
                    string key = dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["Key"].ToString(); 
                    if ( string.CompareOrdinal( key, displayItem.Key ) != 0 ) 
                        continue
 
                    dataItem.Selected = true
                    break
                } 
            } 

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 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 01 Feb 2008, 01:58 PM
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,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Thomas
Top achievements
Rank 1
answered on 01 Feb 2008, 05:44 PM
Excellent! That did the trick.
Tags
Grid
Asked by
Thomas
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or