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

GridClientSelectColumn Persistence state

8 Answers 680 Views
Grid
This is a migrated thread and some comments may be shown as answers.
alekhya
Top achievements
Rank 1
alekhya asked on 16 Feb 2011, 03:38 PM
Hello 

I am using a gridview which is having GridClientSelectColumn.
here checkbox value is not persistent in postback 
in radgrid i am using EnablePostBackOnRowClick="true" .
reason  why i am using  EnablePostBackOnRowClick="true" is 
1.when ever user select the checkbox i need to show the data in asp control DetailsView 
if i am not setting EnablePostBackOnRowClick="true" i am unable to show the data in DetailsView 
Here user can select multipul checkboxes
Fallowing code snippet i am using 
<telerik:RadGrid runat="server" ID="radgvInbox"  AutoGenerateColumns="False"  DataSourceID="LinqDataSource1"
            AllowMultiRowSelection="true"    OnItemCommand="radgrid1_ItemCommand" OnPreRender="radgrid1_PreRender"  >
              
              <ClientSettings  Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true" AllowDragToGroup="true"  EnableRowHoverStyle="true" ClientEvents-OnRowSelected="onGridRowSelected">
                 <Selecting AllowRowSelect="true" UseClientSelectColumnOnly="true" />
               </ClientSettings>
protected void radgrid1_ItemCommand(object source, GridCommandEventArgs e)
 {
     ArrayList selectedItems;
     if (Session["selectedItems"] == null)
     {
         selectedItems = new ArrayList();
     }
     else
     {
         selectedItems = (ArrayList)Session["selectedItems"];
     }
     if (e.CommandName == RadGrid.SelectCommandName &&
         e.Item is GridDataItem)
     {
         GridDataItem dataItem = (GridDataItem)e.Item;
         string MessageID = dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["MessageID"].ToString();
         selectedItems.Add(MessageID);
         Session["selectedItems"] = selectedItems;
     }
     if (e.CommandName == RadGrid.DeselectCommandName && e.Item is GridDataItem)
     {
         GridDataItem dataItem = (GridDataItem)e.Item;
         string MessageID = dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["MessageID"].ToString();
         selectedItems.Remove(MessageID);
         Session["selectedItems"] = selectedItems;
     }
 }
 protected void radgrid_PreRender(object sender, EventArgs e)
 {
     if (Session["selectedItems"] != null)
     {
         ArrayList selectedItems = (ArrayList)Session["selectedItems"];
         Int16 stackIndex;
         for (stackIndex = 0; stackIndex <= selectedItems.Count - 1; stackIndex++)
         {
             string curItem = selectedItems[stackIndex].ToString();
             foreach (GridItem item in radgvInbox.MasterTableView.Items)
             {
                 if (item is GridDataItem)
                 {
                     GridDataItem dataItem = (GridDataItem)item;
                     if (curItem.Equals(dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["MessageID"].ToString()))
                     {
                         dataItem.Selected = true;
                         break;
                     }
                 }
             }
         }
     }
 }
  
}

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Feb 2011, 09:31 AM
Hello Alekhya,

I found one forum post discussing the similar issue SelectedItems not persisted with EnablePostBackOnRowClick , please go through it and see if it helps.

Thanks,
Princy.
0
Bhuvan
Top achievements
Rank 1
answered on 01 Mar 2011, 06:54 AM
Hi Princy,

I too have the same problem.. But in ur link...I am not able to download the file "selection.zIp"  even an online documentation raising an error.. will u please provide the same file for download please,
0
Princy
Top achievements
Rank 2
answered on 01 Mar 2011, 10:53 AM
Hello Bhuvan,

Here is the code in that attached file.
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
            <clientsettings enablepostbackonrowclick="true">
            <Selecting AllowRowSelect="true" />
        </clientsettings>
 </telerik:RadGrid>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

C#:
protected void RadGrid1_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)
  {
      RadGrid1.DataSource = new object[] { 1, 2, 3, 4, 5 };
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
      Response.Write(RadGrid1.SelectedItems.Count);
  }

And as mentioned in that link client selection will be lost when the grid is rebound. You can find more details on how to persist the grid selection when rebinding in the following documentation.
Persisting the selected rows client-side on sorting/paging/filtering/grouping
Persisting the selected rows server-side on sorting/paging/filtering/grouping

Thanks,
Princy.
0
Bhuvan
Top achievements
Rank 1
answered on 05 Mar 2011, 11:37 AM

Hi Princy,
I seen ur links and I got an idea like this
Let me explain my code


So this is my client side code
------------------------------

 

 

<

 

 

telerik:RadGrid  runat="server" ID="RadGrid1"  AutoGenerateColumns="False">

 

<ClientSettings  EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">

<Selecting AllowRowSelect="True"/><Scrolling AllowScroll="false"/>
<Resizing AllowColumnResize="True" />

 

</ClientSettings>

 

<MasterTableView TableLayout="Fixed" GroupLoadMode="Client"
AdditionalDataFieldNames="Date" Width="100%">

 

<Columns>

columns/////

 

</columns>

 

</MasterTableView>

 

</telerik:RadGrid>
And my server side code is
---------------------------

if

 

 

(e.CommandName == "RowClick" && e.Item is Telerik.Web.UI.GridDataItem )

 

{

 

e.Item.Selected =

 

true ; //

 

 

}
e.Item.Selected = true; //
because of above line my item is getting checked but the problem is multiple checking is not happening..will u please suggest the code changes please......

 

 

 

0
Princy
Top achievements
Rank 2
answered on 08 Mar 2011, 01:42 PM
Hello Bhuvan,

You can select multiple rows(using ctrl-click) if you have set 'AllowMultiRowSelection="true" for RadGrid. If you dont want to use ctrl-click on the rows, then one suggestion is to try the following code library to persist the multiple selection on clikcing the grid rows.
Selecting/Deselecting rows on clicking row itself and without interfering selected items

Note: It will also work if you have set EnablePostBackOnRowClick="true"

Thanks,
Princy.
0
Lokesh
Top achievements
Rank 1
answered on 24 Jun 2013, 01:55 PM
Hi Princy,
I know this thread is very old but found it useful for my problem. So replying to you.
As mentioned in Persisting the selected rows client-side on sorting/paging/filtering/grouping article, I tried that approach.
It works just perfect as far as the visualisation is concerned.
User does get a feel that items from different pages are still selected.

But when we move to do some code for these selected items, all we get is the items on current page only.

I mean, on first page I have selected 4 rows, on second page I have selected 3 rows, on third page I have selected 1 row.
On a button click (button is outside the grid), when I try to loop through these selected items collection, I don't get all those selected items.
All I get are the items on the current selected page.

I cannot use
 foreach (GridDataItem item in RadGrid1.SelectedItems)
{
..../// Code here
}

RadGrid1.SelectedItems returns selected items on the current page only and not my selected items.

Can you please help me on this??
Any help appreciated.

Thanks,
Lok..
0
Lokesh
Top achievements
Rank 1
answered on 25 Jun 2013, 06:36 AM
Hi Princy,
I know this thread is very old but found it useful for my problem. So replying to you.
As mentioned in Persisting the selected rows client-side on sorting/paging/filtering/grouping article, I tried that approach.
It works just perfect as far as the visualisation is concerned.
User does get a feel that items from different pages are still selected.

But when we move to do some code for these selected items, all we get is the items on current page only.

I mean, on first page I have selected 4 rows, on second page I have selected 3 rows, on third page I have selected 1 row.
On a button click (button is outside the grid), when I try to loop through these selected items collection, I don't get all those selected items.
All I get are the items on the current selected page.

I cannot use
 foreach (GridDataItem item in RadGrid1.SelectedItems)
{
..../// Code here
}

RadGrid1.SelectedItems returns selected items on the current page only and not my selected items.

Can you please help me on this??
Any help appreciated.

Thanks,
Lok..
0
Lokesh
Top achievements
Rank 1
answered on 25 Jun 2013, 06:37 AM
Hi Princy,
I know this thread is very old but found it useful for my problem. So replying to you.
As mentioned in Persisting the selected rows client-side on sorting/paging/filtering/grouping article, I tried that approach.
It works just perfect as far as the visualisation is concerned.
User does get a feel that items from different pages are still selected.

But when we move to do some code for these selected items, all we get is the items on current page only.

I mean, on first page I have selected 4 rows, on second page I have selected 3 rows, on third page I have selected 1 row.
On a button click (button is outside the grid), when I try to loop through these selected items collection, I don't get all those selected items.
All I get are the items on the current selected page.

I cannot use
 foreach (GridDataItem item in RadGrid1.SelectedItems)
{
..../// Code here
}

RadGrid1.SelectedItems returns selected items on the current page only and not my selected items.

Can you please help me on this??
Any help appreciated.

Thanks,
Lok..
Tags
Grid
Asked by
alekhya
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Bhuvan
Top achievements
Rank 1
Lokesh
Top achievements
Rank 1
Share this question
or