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

Checkbox getting unchecked after filter

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kavitha
Top achievements
Rank 1
Kavitha asked on 16 Jan 2014, 07:36 AM
Hi All

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.

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 20 Jan 2014, 07:21 AM
Hello Kavitha,

I have already provided an answer in the official support ticket you have opened regarding this matter
. Please give the suggestion there a try and let us know if it helps you resolve the problem.

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
Kavitha
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or