I have a radgrid with ClientSelectColumn.
I select a row on first page of the grid, move to second page select 3 rows on second page.
When I come back to first page, my selection on the first page disappears. I mean the selection does not persist.
So I tried what has been said in this post. It works very well as far as visualisation is concerned. It does show that I have my rows selected from different pages.
But when on a button click (outside the grid) I try to loop through this collection, all I get is the records from current selected page and not all the rows selected from different pages.
foreach (GridDataItem item in RadGrid1.SelectedItems)
{
..// Code here
}
RadGrid1.SelectedItems gives rows from the current selected page only and not the entire selection.
Will you please help me with this?
Any help appreciated.
Thanks,
Lok..
6 Answers, 1 is accepted

Thanks for your quick reply but this solution is not working for me.
I tried Persistence of checked items on page navigation - Client Side
Why is that I can see the rows selected from different pages but cannot loop through the SelectedItems collection?
All I get are the selected rows of current selected page.
I mean, if I have selected rows from 3 different pages and currently I am on page 2, then in SelectedItems collection, I get rows from page 2 only and not the all the rows selected.
Would you please explain me this and help me with the solution?
Thanks,
Lok..

I'm not sure what is causing that issue,below is a code i tried,which displays the selected rows for all pages.Please have a try.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowPaging
=
"True"
PageSize
=
"5"
DataSourceID
=
"SqlDataSource1"
AutoGenerateColumns
=
"True"
OnPreRender
=
"RadGrid1_PreRender"
>
<
MasterTableView
DataKeyNames
=
"OrderID"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"OrderID"
HeaderText
=
"OrderID"
UniqueName
=
"Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"CheckBox1"
runat
=
"server"
AutoPostBack
=
"True"
CausesValidation
=
"false"
OnCheckedChanged
=
"CheckBox1_CheckedChanged"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<%--To display the rows checked--%>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text
=
""
></
asp:Label
>
C#:
public
string
_SelectedID
{
set
{
ViewState[
"SelectedID"
] = value;
}
get
{
if
(ViewState[
"SelectedID"
] !=
null
)
{
return
Convert.ToString(ViewState[
"SelectedID"
]);
}
else
{
return
",0,"
;
}
}
}
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
foreach
(GridDataItem item
in
RadGrid1.Items)
{
if
(_SelectedID.Contains(
","
+ Convert.ToInt32(item.GetDataKeyValue(
"OrderID"
)).ToString() +
","
))
{
((CheckBox)item.FindControl(
"CheckBox1"
)).Checked =
true
;
}
}
}
protected
void
CheckBox1_CheckedChanged(
object
sender, EventArgs e)
{
CheckBox CheckBox1 = sender
as
CheckBox;
GridDataItem item = (GridDataItem)CheckBox1.NamingContainer;
int
ID = Convert.ToInt32(item.GetDataKeyValue(
"OrderID"
));
if
(CheckBox1.Checked)
{
_SelectedID += ID.ToString() +
","
;
Label1.Text = _SelectedID.ToString();
//To display the rows checked Using DatakeyValue of a column
}
else
{
_SelectedID += _SelectedID.Replace(ID.ToString() +
","
,
""
);
}
}
Thanks,
Princy

Thanks you so much for your support.
I should better post my code here that will explain the problem.
Here is my aspx:
<telerik:RadButton ID="btnProposal" runat="server" Text="Proposal Run" OnClick="btnProposal_Click" Enabled="false" />
<telerik:RadGrid ID="rgGiroPayments" runat="server" OnNeedDataSource="rgGiroPayments_NeedDataSource" AllowMultiRowSelection="true" pagesize="50" OnItemDataBound="rgGiroPayments_ItemDataBound" ShowFooter="True" CssClass="GridHieght">
<MasterTableView GroupLoadMode="Client" ShowGroupFooter ="true" ClientDataKeyNames="AP_InvoiceID">
<Columns>
<telerik:GridBoundColumn DataField="AP_InvoiceID" HeaderText="AP_InvoiceID" Display="false" UniqueName="AP_InvoiceID">
</telerik:GridBoundColumn>
/***Few More Columns*****/
<telerik:GridClientSelectColumn UniqueName="Select">
</telerik:GridClientSelectColumn>
</Columns>
</MasterTableView>
<GroupingSettings CaseSensitive="False" />
<ClientSettings
Selecting-AllowRowSelect="true" AllowDragToGroup="false" Scrolling-AllowScroll="true" Scrolling-UseStaticHeaders="true" ClientEvents-OnMasterTableViewCreating="SetGridHeight">
<ClientEvents OnRowCreated="rgGiroPayments_RowCreated"
OnRowSelected="rgGiroPayments_RowSelected"
OnRowDeselected="rgGiroPayments_RowDeselected" OnGridCreated="GridCreated" />
</ClientSettings>
</telerik:RadGrid>
<script type="text/javascript">
var selected = {};
function rgGiroPayments_RowSelected(sender, args) {
var mailID = args.getDataKeyValue("AP_InvoiceID");
if (!selected[mailID]) {
selected[mailID] = true;
}
}
function rgGiroPayments_RowDeselected(sender, args) {
var mailID = args.getDataKeyValue("AP_InvoiceID");
if (selected[mailID]) {
selected[mailID] = null;
}
}
function rgGiroPayments_RowCreated(sender, args) {
var mailID = args.getDataKeyValue("AP_InvoiceID");
if (selected[mailID]) {
args.get_gridDataItem().set_selected(true);
}
}
function GridCreated(sender, eventArgs) {
var masterTable = sender.get_masterTableView(),
headerCheckBox = $telerik.$(masterTable.HeaderRow).find(":checkbox")[0];
if (headerCheckBox) {
headerCheckBox.checked = masterTable.get_selectedItems().length == masterTable.get_pageSize();
}
}
</script>
Here is my .cs C#
protected void btnProposal_Click(object sender, EventArgs e)
{
foreach (GridDataItem item in rgGiroPayments.SelectedItems)
{
// Here in rgGiroPayments.SelectedItems
// I get rows only from current page though on UI I have rows selected from different pages.
}
}
I have to iterate through grid selected items as I have some template columns whose controls I need to find in order to get their values.
Now can you please tell me what is wrong with my code?
Please see the attached files for reference.
Thanks,
Lok..

Any update on my problem ?
Thanks,
Lok..
You can check the following code-library to achieve your requirement:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/get-selected-items-through-all-pages.aspx
Hope this helps. Please give it a try and let me know if it works for you.
Regards,
Eyup
Telerik