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

Select all + persist selection + multipage

1 Answer 103 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Marnix Bouwman
Top achievements
Rank 2
Marnix Bouwman asked on 01 Dec 2009, 08:57 AM
Hi I have this radgrid showing 10 items per page where I want to have a column with checkboxes.
When I check some checkboxes on page 1, I want to go to page 4 and select some more checkboxes.
And then go back to page 1 and the selected checkboxes should still be selected.
I have this working.

Now I want a select all checkbox which selects, well.... All records... I got it so far so it will select all records on the current page, but not on the other pages.

I've set it up like this:

<telerik:radgrid id="RadUsers" allowmultirowselection="true" showfooter="True" runat="server" showstatusbar="True" onneeddatasource="RadUsers_NeedDataSource" gridlines="None" allowpaging="True" pagesize="10" skin="Vista" allowfilteringbycolumn="True" autogeneratecolumns="False" >
    <mastertableview showfooter="True" datakeynames="UserID"  >
        <columns>
            <telerik:gridtemplatecolumn allowfiltering="false">
                <headertemplate>
                    <asp:checkbox id="headerChkbox" oncheckedchanged="ToggleSelectedState" autopostback="True" runat="server"></asp:checkbox>
                </headertemplate>
                <itemtemplate>
                    <asp:checkbox id="cbChecked" runat="server" autopostback="true" oncheckedchanged="OnCheckedChangedEvent" />
                </itemtemplate>
            </telerik:gridtemplatecolumn>
...

And:

        Private ReadOnly Property UsersChecked() As Hashtable
            Get
                Dim res As Object = ViewState("_cc")
                If (res Is Nothing) Then
                    res = New Hashtable
                    ViewState("_cc") = res
                End If
                Return CType(res, Hashtable)
            End Get
        End Property

....

        Protected Sub RadUsers_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadUsers.ItemDataBound
            If TypeOf e.Item Is GridDataItem Then
                Dim item As GridDataItem = CType(e.Item, GridDataItem)
                Dim box As CheckBox = CType(item.FindControl("cbChecked"), CheckBox)
                Dim isChecked As Object = Nothing

                isChecked = UsersChecked(item("UserID").Text)

                If Not (isChecked Is Nothing) Then
                    box.Checked = CType(isChecked, Boolean) = True
                End If
            End If
        End Sub


        Protected Sub ToggleSelectedState(ByVal sender As Object, ByVal e As EventArgs)
            Dim target As Hashtable = Nothing
            target = UsersChecked

            If (CType(sender, CheckBox)).Checked Then
                For Each dataItem As GridDataItem In RadUsers.MasterTableView.Items
                    CType(dataItem.FindControl("cbChecked"), CheckBox).Checked = True
                    'dataItem.Selected = True
                    target(dataItem("UserID").Text) = True
                Next
            Else
                For Each dataItem As GridDataItem In RadUsers.MasterTableView.Items
                    CType(dataItem.FindControl("cbChecked"), CheckBox).Checked = False
                    'dataItem.Selected = False
                    target(dataItem("UserID").Text) = Nothing
                Next
            End If
        End Sub


        Sub OnCheckedChangedEvent(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim box As CheckBox = CType(sender, CheckBox)
            Dim item As GridDataItem = CType(box.NamingContainer, GridDataItem)
            Dim target As Hashtable = Nothing

            target = UsersChecked

            If box.Checked Then
                target(item("UserID").Text) = True
            Else
                target(item("UserID").Text) = Nothing
            End If
        End Sub




1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 03 Dec 2009, 02:32 PM
Hello Marnix,

You may consider the client-side approach with 'SelectAll' option in built-in GridClientSelectColumn demonstrated in this topic from the online documentation. Thus you should attain the desired result.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Chart (Obsolete)
Asked by
Marnix Bouwman
Top achievements
Rank 2
Answers by
Sebastian
Telerik team
Share this question
or