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());
}
}