PDA

View Full Version : [CLOSED] Get Checked items of checkbox group



mohan.bizbites
Oct 21, 2013, 3:59 PM
Hi Team,

We are working on checking checkbox group items from code behind and suspending its events, we are doing that by calling javascript function.
It is working fine up to checking. But when we are trying to get the checked items in another event the checkbox group is returning zero as count

We summarized the code to reproduce the issue. But actual scenario is while loading usercontrol we are doing checking. And in another button event we are trying to get the checked items.
How can we achive this functionality?

Here is the code to reproduce the issue



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CheckGroup.aspx.cs" Inherits="Ext2._2Practice.CheckGroup" %>


<%@ Register Namespace="Ext.Net" Assembly="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var SetCheckBoxCheckValues = function (radio, isChecked) {
if (radio) {
radio.suspendEvents(false);
radio.setValue(isChecked);
radio.resumeEvents();
}
};
</script>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{


}
protected void btnSet_OnEvent(object sender, DirectEventArgs e)
{
ResourceManager1.AddScript("SetCheckBoxCheckValues(" + chkSunday.ClientID + "," + true.ToString().ToLower() + ");");
}
protected void btnGet_OnEvent(object sender, DirectEventArgs e)
{
List<string> lstSelectedDays = new List<string>();


chkGroupWeekDaysOption.CheckedItems.ForEach(delega te(Checkbox checkbox)
{
lstSelectedDays.Add(checkbox.BoxLabel);
});
int count = lstSelectedDays.Count;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:FieldContainer ID="fcWeekDaysOptions" Padding="50" runat="server" LabelWidth="120" LabelAlign="Left" FieldLabel="Occurence Days">
<Items>
<ext:CheckboxGroup Width="350" ID="chkGroupWeekDaysOption" runat="server"
ColumnsNumber="4">
<Items>
<ext:Checkbox ID="chkSunday" runat="server" BoxLabel="Sunday" />
<ext:Checkbox ID="chkMonday" runat="server" BoxLabel="Monday" />
<ext:Checkbox ID="chkTuesday" runat="server" BoxLabel="Tuesday" />
<ext:Checkbox ID="chkWednesday" runat="server" BoxLabel="Wednesday" />
<ext:Checkbox ID="chkThursday" runat="server" BoxLabel="Thursday" />
<ext:Checkbox ID="chkFriday" runat="server" BoxLabel="Friday" />
<ext:Checkbox ID="chkSaturday" runat="server" BoxLabel="Saturday" />
</Items>
</ext:CheckboxGroup>
</Items>
</ext:FieldContainer>
<ext:FieldContainer ID="FieldContainer1" Padding="50" runat="server" LabelWidth="120" LabelAlign="Left" FieldLabel="Occurence Days">
<Items>
<ext:Button ID="btnSet" runat="server" StyleSpec="margin-right:50px;" Text="Set">
<DirectEvents>
<Click OnEvent="btnSet_OnEvent"></Click>
</DirectEvents>
</ext:Button>
<ext:Button ID="btnGet" runat="server" Text="Get">
<DirectEvents>
<Click OnEvent="btnGet_OnEvent"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:FieldContainer>
</form>
</body>
</html>




Please contact if you need more information

Daniil
Oct 21, 2013, 5:02 PM
Hi @mohan.bizbites,

Please call

radio.syncHiddenState();
after the setValue call.