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

[Solved] Access GridItems on different page (AllowPaging is enabled in grid)

3 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cade
Top achievements
Rank 1
Cade asked on 01 Apr 2009, 07:04 PM
Here is my my aspx page. I have paging set to true on the grid (which is working properly). I want to toggle the selected state of each of the checkboxes in the GridItems instead of just the GridItems on the current page.

Each GridItem has a chkInclude (its an ItemTemplate).

ASPX Code:
<asp:CheckBox ID="chkIncludeAll" runat="server" AutoPostBack="true" OnCheckedChanged="chkIncludeAll_OnCheckedChanged"
                    Text="Select/Deselect All" />
                <telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="false" AllowPaging="True" AllowSorting="true"
                    Width="434px" Height="300px" BorderStyle="None" HorizontalAlign="Left" runat="server"
                    OnNeedDataSource="RadGrid1_NeedDataSource">
                    <ClientSettings Scrolling-AllowScroll="false">
                        <ClientEvents OnRowSelected="RadGrid1_RowSelected" />
                    </ClientSettings>
                    <MasterTableView ClientDataKeyNames="TimeZoneIndex,Roving" PageSize="15">
                        <Columns>
                            <telerik:GridTemplateColumn HeaderText="Include" HeaderTooltip="Include" UniqueName="Include">
                                <HeaderStyle Width="20px" />
                                <ItemTemplate>
                                    <asp:CheckBox ID="chkInclude" runat="server" />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="EmployeeId" UniqueName="EmployeeId" HeaderText="Id"
                                HeaderTooltip="Id">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="LastName" UniqueName="LastName" HeaderText="Last Name"
                                HeaderTooltip="Last Name">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName" HeaderText="First Name"
                                HeaderTooltip="First Name">
                            </telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>

C# Code:
protected void chkIncludeAll_OnCheckedChanged(Object sender, EventArgs e)
        {
            CheckBox checkboxIncludeAll = sender as CheckBox;
            if (checkboxIncludeAll is CheckBox)
            {
                foreach (GridItem item in RadGrid1.Items)
                {
                    if (item.ItemType != GridItemType.Item && item.ItemType != GridItemType.AlternatingItem)
                    {
                        continue;
                    }

                    CheckBox checkboxIncludeSingle = item.FindControl("chkInclude") as CheckBox;
                    if (checkboxIncludeSingle is CheckBox)
                    {
                        checkboxIncludeSingle.Checked = checkboxIncludeAll.Checked;
                    }
                }
            }
        }

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Apr 2009, 07:15 AM
Hello Cade,

You can try out following code in the PreRender event of the grid so as to toggle selected state of checkbox across pages in the grid:
c#:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    {         
           foreach (GridItem item in RadGrid1.Items) 
            { 
                if (item.ItemType != GridItemType.Item && item.ItemType != GridItemType.AlternatingItem) 
                { 
                    continue
                } 
 
                CheckBox checkboxIncludeSingle = item.FindControl("chkInclude"as CheckBox; 
                if (checkboxIncludeSingle is CheckBox) 
                { 
                    checkboxIncludeSingle.Checked = chkIncludeAll.Checked; 
                } 
            }         
    } 

Thanks
Princy.
0
Cade
Top achievements
Rank 1
answered on 02 Apr 2009, 01:06 PM
Thanks Princy...Works like a charm.
0
Cade
Top achievements
Rank 1
answered on 02 Apr 2009, 05:33 PM
Well...that worked for showing the items selected when the page loads but I actually need them selected on the previous/subsequent pages.

For example, when the user selects the chkIncludeAll checkbox, it should select all the items on all the pages. The second part of my problem is that I need to be able to determine the checked state of all the items in the grid. I might have 2000 items in the grid with only 10 items shown per page. If the user selects thte chkIncludeAll checkbox, i want to select all of the items on all of the pages because I am going to write the state of the items to the database when the user saves which items they have selected (there is a save button on the page).
Tags
Grid
Asked by
Cade
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Cade
Top achievements
Rank 1
Share this question
or