RadGrid does not preserved state

4 posts, 0 answers
  1. Amitkumar
    Amitkumar avatar
    66 posts
    Member since:
    Aug 2009

    Posted 15 Dec 2009 Link to this post

    Hi All,

    I am using following code, after loading grid data those record are displayed in grid, the real problem is that once i unchecked any record from first page(i.e. grid first page), and move to next page and again come back the first page, it will not display unchecked record, why?

    <telerik:RadGrid ID="rgEventResult" Width="100%" runat="server" AllowFilteringByColumn="false"
                    AllowPaging="True" AllowSorting="True" GridLines="None" ShowGroupPanel="false"
                    AllowMultiRowSelection="true" AutoGenerateColumns="False" Height="370px" PageSize="10"
                    OnNeedDataSource="rgEventResult_NeedDataSource" OnItemCreated="rgEventResult_ItemCreated"
                    OnItemDataBound="rgEventResult_ItemDataBound">
                    <HeaderContextMenu EnableEmbeddedSkins="False" />
                    <ItemStyle Wrap="True" />
                    <PagerStyle AlwaysVisible="True" ShowPagerText="true" Mode="NextPrevAndNumeric" />
                    <MasterTableView DataKeyNames="Id" ItemStyle-Wrap="true" TableLayout="Auto">
                        <Columns>
                            <telerik:GridClientSelectColumn UniqueName="SelectColumn" HeaderStyle-Width="25px">
                                <HeaderStyle Width="25px"></HeaderStyle>
                            </telerik:GridClientSelectColumn>
                            <telerik:GridBoundColumn UniqueName="EventAttendeeId" HeaderText="Event Attendee Id"
                                DataField="EventAttendeeId" Display="false" />
                            <telerik:GridBoundColumn DataField="Email" HeaderText="Email" UniqueName="EventEmail" />
                            <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" UniqueName="EventFirstName" />
                            <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" UniqueName="EventLastName" />
                            <telerik:GridBoundColumn DataField="CompanyName" HeaderText="Company" UniqueName="EventCompanyName" />
                            <telerik:GridBoundColumn DataField="Status" HeaderText="Registration Status" UniqueName="EventStatus" />
                            <telerik:GridBoundColumn DataField="EventTitle" HeaderText="Event Title" UniqueName="EventTitle" />
                        </Columns>
                    </MasterTableView>
                    <ClientSettings AllowColumnHide="false" AllowColumnsReorder="false" AllowDragToGroup="false"
                        ReorderColumnsOnClient="false">
                        <Selecting AllowRowSelect="True" />
                        <Resizing ClipCellContentOnResize="false" AllowColumnResize="true" ResizeGridOnColumnResize="true" />
                        <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true" ScrollHeight="100%" />
                    </ClientSettings>
                </telerik:RadGrid>

    protected void rgEventResult_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
            {
                ContactListDetailService.ContactListDetailClient proxyDetail = new ContactListDetailService.ContactListDetailClient();
                List<System.Guid> eventIds = new List<Guid>();
                List<System.Guid> statusIds = new List<Guid>();

                if (Session["EventIds"] != null)
                {
                    eventIds = Session["EventIds"] as List<System.Guid>;
                }

                if (Session["StatusIds"] != null)
                {
                    statusIds = Session["StatusIds"] as List<System.Guid>;
                }

                try
                {
                    epp2ClientPL.ContactListDetailProperties[] details = proxyDetail.LoadByEventAndStatusIds(eventIds.ToArray(), statusIds.ToArray());
                    rgEventResult.DataSource = details; // proxyDetail.LoadByEventAndStatusIds(eventIds, statusIds);
                    lblTotal.Text = details.Count().ToString();
                }
                catch
                { }
                finally
                {
                    if (proxyDetail != null)
                    {
                        proxyDetail.Close();
                        proxyDetail = null;
                    }
                }
            }

    protected void rgEventResult_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem dataItem = (GridDataItem)e.Item;
                    dataItem.Selected = true;
                }
            }

    waiting for reply


    Thanks & Regards,
    Dharmesh





  2. Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 15 Dec 2009 Link to this post

    Although it is specifically for selected items I think the logic in this article can help you persist the state of these items through the paging etc. of the RadGrid. I believe this is the best way to go at this :)
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Amitkumar
    Amitkumar avatar
    66 posts
    Member since:
    Aug 2009

    Posted 15 Dec 2009 Link to this post

    Hi Schulurk,

    I am using NeedDataSource event then still that logic works, or there is no such inbuilt property that maintain the state of check or uncheck items.


    Reply me.


    Thanks & Regards
    Dharmesh
  5. Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 16 Dec 2009 Link to this post

    I don't think there's another way to preserve the state of check-boxes. An alternative would be to perhaps on the changed event of the checkbox load its current state into ViewState and upon paging extract all of the states for items in that particular page.
Back to Top