I tried the below link
Persisting CheckBox control state in GridTemplateColumn on rebind
But there is Autopostback = "true" in the checkbox template which causes the selected checkbox unchecked. It is not working.
<telerik:RadGrid ID="RGBankCash" runat="server"
GridLines="None" Skin="Vista" Width="500px"
OnItemDataBound="RGBankCash_ItemDataBound" >
<AlternatingItemStyle BackColor = "White" />
<ClientSettings > <Selecting AllowRowSelect="true" /> </ClientSettings>
<MasterTableView AutoGenerateColumns="False" DataKeyNames="CAKey" AllowFilteringByColumn="True" >
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="CAKey" DataType="System.Int32"
HeaderText="CAKey" ReadOnly="True" SortExpression="CAKey"
UniqueName="CAKey" Visible="False">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="IsTrue" DataType="System.Int32"
HeaderText="IsTrue" ReadOnly="True" SortExpression="IsTrue"
UniqueName="IsTrue" Visible="False">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn AllowFiltering="false" UniqueName="MasterTemplate" HeaderText="Select">
<HeaderTemplate>
<input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" runat="server" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<%
-- <telerik:radwindow runat="server" id="RadWindow1" visibleonpageload="false">
<ContentTemplate>
--
%>
<%
-- <asp:UpdatePanel ID="UpdatePanel1" runat="server" OnUnload="UpdatePanel_Unload">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RGBankCash" EventName="Click" />
</Triggers>
<contenttemplate>--
%>
<asp:CheckBox runat="server" ID="chkUpdate" OnCheckedChanged="CheckChanged" />
<%
-- </contenttemplate>
</asp:UpdatePanel > --
%>
<%
-- </ContentTemplate>
</telerik:radwindow> --
%>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="TransMonth"
HeaderText="Trans Month" UniqueName="TransMonth">
<ItemTemplate>
<asp:Label ID="TransMonthLabel" runat="server"
Text='<%# Eval("TransMonth") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="250px" />
</telerik:GridTemplateColumn>
protected void CheckChanged(Object sender, System.EventArgs e)
{
CheckBox box = (CheckBox)sender;
GridDataItem item = (GridDataItem)box.NamingContainer;
Hashtable target = null;
if (item.OwnerTableView.DataKeyNames.ToString() == "CAKey")
{
target = CAKeyChecked;
}
if (box.Checked)
{
target[item[
"CAKey"].Text] = true;
}
else
{
target[item[
"CAKey"].Text] = null;
}
}
private Hashtable CAKeyChecked
{
get
{
object res = ViewState["_cc"];
if (res == null)
{
res =
new Hashtable();
ViewState[
"_cc"] = res;
}
return (Hashtable)res;
}
}
protected void RGBankCash_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
DataSet ds1 = new DataSet();
ds1 = SelectDistinctCompanySubmitted();
string transmonth = this.rcboMonth.SelectedValue + this.rcboFiscalYear.SelectedValue;
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
//foreach (DataRow r in ds1.Tables[0].Rows)
//{
string compkey = ds1.Tables[0].Rows[i]["companykey"].ToString();
bool chk = FindoddCompany(Int32.Parse(compkey));
if (chk == true)
{
//Trigger Reject Email to Accountant
// CommonClass.TriggerEmailToAccByCHQ(compkey, transmonth);
//Reset Submit status
//conn.Open();
//SqlCommand cmd1 = new SqlCommand("Update CashAnalysisDetail_Tbl Set IsSubmitted = 0 where CompanyKey = " + Int32.Parse(compkey) + " and TransMonth = '" + transmonth + "'", conn);
//cmd1.ExecuteNonQuery();
//conn.Close();
}
else
{
if (e.Item is GridDataItem)
{
string sqlst1 = "SELECT CAKey from CashAnalysisDetail_Tbl where CompanyKey = " + compkey + " and Transmonth = '" + transmonth + "' and IsSubmitted = 1 and ReportStatus='A'";
cn =
new SqlConnection(connString);
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = sqlst1;
cmd.Connection = cn;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
DataSet ds = new DataSet();
adapter.Fill(ds,
"dt1");
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
{
GridDataItem dataItem = (GridDataItem)e.Item;
string CAKey = ds.Tables[0].Rows[j]["CAKey"].ToString();
if (Int32.Parse((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CAKey"].ToString()) == Int32.Parse(CAKey))
{
dataItem.BackColor = System.Drawing.
Color.Yellow;
dataItem.Font.Bold =
true;
}
 
}
}
}
}
 
if (e.Item is GridDataItem)
{
GridDataItem item = e.Item as GridDataItem;
CheckBox box = (CheckBox)item.FindControl("cbChecked");
object isChecked = null;
if (item.OwnerTableView.DataMember == "CAKey")
{
isChecked = CAKeyChecked[item[
"CAKey"].Text];
}
//if (item.OwnerTableView.DataMember == "Customers1")
//{
// isChecked = Customers1Checked[item["CustomerID"].Text];
//}
//if (item.OwnerTableView.DataMember == "Customers2")
//{
// isChecked = Customers2Checked[item["CustomerID"].Text];
//}
if (isChecked != null)
{
box.Checked = (
bool)isChecked == true;
}
}
}
Please help me.