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

CheckBox In RadGrid Telerik

1 Answer 776 Views
Grid
This is a migrated thread and some comments may be shown as answers.
doni
Top achievements
Rank 1
doni asked on 27 Oct 2015, 07:48 AM

Hi,

I'm using radgrid with checkbox to select row in there. I have a lot of data, and I use paging in my Grid.

I think that my code is OK, when i check one row or more. When i check chekbox header, i think that my all of my data's are checked but actually

my data in other pages are not checked.

Please advise,

Thank you so much

 

Bellow is my code in aspx :

<telerik:RadGrid ID="RgTrial" runat="server" OnNeedDataSource="RgTrial_NeedDataSource" AutoGenerateColumns="false" ClientSettings-Resizing-AllowColumnResize="false"
                                ClientSettings-Resizing-AllowResizeToFit="false" ClientSettings-Resizing-EnableRealTimeResize="false" Width="1046" Height="550" ClientSettings-Scrolling-AllowScroll="true"
                                ClientSettings-Scrolling-UseStaticHeaders="true" AllowMultiRowSelection="true" AllowFilteringByColumn="true" GroupingSettings-CaseSensitive="false" AllowPaging="True" PageSize="50" EnableEmbeddedSkins="false" Skin="CustomSkin">
                                 
                                <MasterTableView DataKeyNames="Nomor,BatchNo,BatchDate,SO,SOType,SODate,BusinessUnit,BUName,POCustomer,Customer,SalesID,SalesName,IndexProduct,IndexService,GPMSA,GPMActual
                                    ,Currency,RealAmount,ExchangeRate,Amount,ServiceAmount,CollAmount,Revenue,COGS,GPMAchievement,PctgCommPaid,Formula,Commision,ActiveFlag,EditReason,Calculation,IsFinal">
                                    <Columns>
 
 
                                        <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn" HeaderStyle-Width="45px" ItemStyle-HorizontalAlign="Center" AllowFiltering="false">
                                            <ItemTemplate>
                                                <asp:CheckBox ID="CBSelectRow" runat="server"  AutoPostBack="True" OnCheckedChanged="CBSelectRow_CheckedChanged"  />
                                            </ItemTemplate>
                                            <HeaderTemplate>
                                                <asp:CheckBox ID="CBHeader" runat="server" AutoPostBack="True" OnCheckedChanged="CBHeader_CheckedChanged" />
                                            </HeaderTemplate>
                                        </telerik:GridTemplateColumn>
 
                                        <telerik:GridBoundColumn DataField="NOMOR" HeaderText="No" ReadOnly="true" HeaderStyle-HorizontalAlign="Center" DataType="System.String" HeaderStyle-Width="75" ShowFilterIcon="false" FilterControlWidth="60"
                                            AutoPostBackOnFilter="true" CurrentFilterFunction="EqualTo" ItemStyle-HorizontalAlign="Center" AllowFiltering="false">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="BatchNo" HeaderText="Batch No" ReadOnly="true" HeaderStyle-HorizontalAlign="Center" DataType="System.String" HeaderStyle-Width="100" ShowFilterIcon="false" FilterControlWidth="85"
                                            AutoPostBackOnFilter="true" CurrentFilterFunction="EqualTo" ItemStyle-HorizontalAlign="Center" AllowFiltering="true">
                                        </telerik:GridBoundColumn>
 

and code behind, i use c# :

 

protected void CBSelectRow_CheckedChanged(object sender, EventArgs e)
       {
           try
           {
               ((sender as CheckBox).NamingContainer as GridItem).Selected = (sender as CheckBox).Checked;
               bool checkHeader = true;
 
               foreach (GridDataItem dataItem in RgTrial.MasterTableView.Items)
               {
                   if (!(dataItem.FindControl("CBSelectRow") as CheckBox).Checked)
                   {
                       checkHeader = false;
 
                       break;
                   }
 
               }
               GridHeaderItem headerItem = RgTrial.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;
               (headerItem.FindControl("CBHeader") as CheckBox).Checked = checkHeader;
           }
 
           catch (Exception x)
           {
               Logger.Instance.LogException(System.Reflection.MethodBase.GetCurrentMethod(), x, true, Helper.Instance.GetUserID());
           }
       }
 
       protected void CBHeader_CheckedChanged(object sender, EventArgs e)
       {
           try
           {
               CheckBox headerCheckBox = (sender as CheckBox);
               foreach (GridDataItem dataItem in RgTrial.MasterTableView.Items)
               {
                   (dataItem.FindControl("CBSelectRow") as CheckBox).Checked = headerCheckBox.Checked;
                   dataItem.Selected = headerCheckBox.Checked;
                   
               }
           }
           catch (Exception x)
           {
               Logger.Instance.LogException(System.Reflection.MethodBase.GetCurrentMethod(), x, true, Helper.Instance.GetUserID());
           }
       }

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 30 Oct 2015, 07:24 AM
Hi Doni,

Please note that only the items on the current page are loaded. I suggest that you examine the RadGridGetAllSelectedItemsImproved.zip sample provided in the following post:
http://www.telerik.com/support/code-library/get-selected-items-through-all-pages#1eTU8nr-GUG8zfGgOGbIcA


The requested functionality would be possible if you put all the record IDs in the collection.

Hope this helps.


Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
doni
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or