PDA

View Full Version : [CLOSED] Why i get checkboxgroup.CheckedItems.Count Always 0 ?



gs_user
Apr 19, 2012, 12:44 AM
<%@ Page Language="C#" %>

<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
for (int i = 0; i <5; i++)
{

Ext.Net.Checkbox cbo = new Ext.Net.Checkbox();
cbo.BoxLabel = "item "+i.ToString();
cbo.AnchorHorizontal = "100%";

cbo.Checked = true;

cbo.InputValue = i.ToString();
cbg1.Items.Add(cbo);
}


}
}

protected void GetCount(object sender, DirectEventArgs e)
{
X.Msg.Alert("Count", this.cbg1.CheckedItems.Count).Show();
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Ext.Net Example</title>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:CheckboxGroup ID="cbg1" runat="server" ColumnsNumber="1" X="5" Y="5" >
<Items>
<%-- <ext:Checkbox ID="Checkbox4" runat="server" BoxLabel="Item 1" />
<ext:Checkbox ID="Checkbox5" runat="server" BoxLabel="Item 2" Checked="true" />
<ext:Checkbox ID="Checkbox6" runat="server" BoxLabel="Item 3" />
<ext:Checkbox ID="Checkbox7" runat="server" BoxLabel="Item 4" />
<ext:Checkbox ID="Checkbox8" runat="server" BoxLabel="Item 5" />--%>
</Items>
</ext:CheckboxGroup>
<ext:Button ID="Button1" runat="server" Text="Show .Count" OnDirectClick="GetCount" />
</form>
</body>
</html>

Daniil
Apr 19, 2012, 3:21 PM
Hi,

The dynamically created Checkboxes should be recreated during DirectEvent.

Example

protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 5; i++)
{
Ext.Net.Checkbox cbo = new Ext.Net.Checkbox();
cbo.BoxLabel = "item " + i.ToString();

cbo.InputValue = i.ToString();
cbg1.Items.Add(cbo);

if (!X.IsAjaxRequest)
{
cbo.Checked = true;
}
}
}

Daniil
Apr 23, 2012, 9:42 AM
If you'd like to avoid re-creating, you can use one of these options:
http://forums.ext.net/showthread.php?18541&p=80063&viewfull=1#post80063