I have a grid with a GridClientSelectColumn column like so:
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:
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.
<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.