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

[Solved] GridClientSelectColumn header checkbox issue

2 Answers 186 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 19 Aug 2013, 11:35 AM
Hi,
i am using GridClientSelectColumn for header checkbox to check all records at one click but when i chek that checkbox it gets checked ,but after refresh all records wiil be unchecked
Below is my code for reference
<telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="True" AllowPaging="True"
         PageSize="5" AllowSorting="True"
         OnNeedDataSource="RadGrid1_NeedDataSource" CellSpacing="0"
         GridLines="None" ShowGroupPanel="True" Skin="Default"
         onitemcommand="RadGrid1_ItemCommand" onprerender="RadGrid1_PreRender">
         <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true"></PagerStyle>
         <ClientSettings Selecting-AllowRowSelect="true" AllowDragToGroup="True" EnablePostBackOnRowClick="true" >
             <Selecting AllowRowSelect="True" UseClientSelectColumnOnly="True"></Selecting>
 
 
         </ClientSettings>
         <MasterTableView DataKeyNames="UserId">
             <Columns>
              
                 <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" />
             </Columns>
             <PagerStyle AlwaysVisible="True"></PagerStyle>
         </MasterTableView>
     </telerik:RadGrid>

Thanks.

2 Answers, 1 is accepted

Sort by
0
Swapnil
Top achievements
Rank 1
answered on 20 Aug 2013, 05:39 AM
and i also want the ids associated with that checkbox on external button click?
Thanks
0
Angel Petrov
Telerik team
answered on 22 Aug 2013, 08:47 AM
Hello Swapnil,

If you rebind the grid it is expected to lose the previously selected items as the controls will recreate in this scenario. That said you should manually persist the selection if rebind is inevitable.

As for extracting the ids of the selected items you can do this in two ways:
  1. Client-side by setting a ClientDataKeyNames="UserId" and extracting the values using JavaScript logic
    function Clicked() {
               var selectedItems = $find('<%=RadGrid1.ClientID%>').get_masterTableView().get_selectedItems();
               for (var i = 0; i < selectedItems.length; i++) {
                   var id = selectedItems[i].getDataKeyValue("CustomerID");
               }
           }
  2. Server-side by setting a DataKeyName like you have already done and using server-side logic for achieving the same.
    protected void Some_Click1(object sender, EventArgs e)
       {
           for (int i = 0; i < RadGrid1.SelectedItems.Count; i++)
           {
               string id=(RadGrid1.SelectedItems[i] as GridDataItem).GetDataKeyValue("UserId").ToString();
           }
       }

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Swapnil
Top achievements
Rank 1
Answers by
Swapnil
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or