GridClientSelectColumn Persistence state

9 posts, 0 answers
  1. alekhya
    alekhya avatar
    8 posts
    Member since:
    Feb 2011

    Posted 16 Feb 2011 Link to this post

    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;
                         }
                     }
                 }
             }
         }
     }
      
    }

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Feb 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bhuvan
    Bhuvan avatar
    50 posts
    Member since:
    Dec 2010

    Posted 01 Mar 2011 Link to this post

    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,
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Mar 2011 Link to this post

    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.
  6. Bhuvan
    Bhuvan avatar
    50 posts
    Member since:
    Dec 2010

    Posted 05 Mar 2011 Link to this post

    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......

     

     

     

  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Mar 2011 Link to this post

    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.
  8. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 24 Jun 2013 Link to this post

    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..
  9. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 25 Jun 2013 Link to this post

    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..
  10. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 25 Jun 2013 Link to this post

    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..
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017