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

RadGrid does not preserved state

3 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amitkumar
Top achievements
Rank 1
Amitkumar asked on 15 Dec 2009, 01:12 PM
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





3 Answers, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 15 Dec 2009, 06:09 PM
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 :)
0
Amitkumar
Top achievements
Rank 1
answered on 16 Dec 2009, 04:25 AM
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
0
Schlurk
Top achievements
Rank 2
answered on 16 Dec 2009, 03:11 PM
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.
Tags
Grid
Asked by
Amitkumar
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Amitkumar
Top achievements
Rank 1
Share this question
or