PDA

View Full Version : [CLOSED] radiogroup.CheckItems is always 0 in dynamically created radiogroup



trezv
Oct 10, 2012, 5:03 PM
Hi,

I'm trying to get selected items from a dynamically created radiogroup, and it always seems to return 0. I used this [http://forums.ext.net/showthread.php?18541-CLOSED-Get-Dynamic-TextField-Text&p=80112&viewfull=1#post80112] code for demo:




<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" TagPrefix="ext" Namespace="Ext.Net" %>
<script runat="server">

protected void Button1_Click(object sender, DirectEventArgs e)
{
this.FormPanel1.Items.AddRange(new[] {
new TextField { ID = "TextField1", FieldLabel = "Item 1" },
new TextField { ID = "TextField2", FieldLabel = "Item 2" },
new TextField { ID = "TextField3", FieldLabel = "Item 3" },
});

var rg = new Ext.Net.RadioGroup()
{
AnchorHorizontal = "100%",
ItemID = "test",
IDMode = Ext.Net.IDMode.Static,
LabelSeparator = " ",
LabelAlign = LabelAlign.Top,
ColumnsNumber = 1
};
rg.FieldLabel = "Question 1";
rg.Add(new Ext.Net.Radio() { ID = "r1", BoxLabel = "Yes" });
rg.Add(new Ext.Net.Radio() { ID = "r2", BoxLabel = "No" });

this.FormPanel1.Items.Add(rg);

this.FormPanel1.Update();
}


protected void Button2_Click(object sender, DirectEventArgs e)
{
var tpl = "Item 1 : {0}<br />Item 2 : {1}<br />Item 3 : {2}<br />Item 4 : {3}";

var item1 = X.GetCmp<TextField>("TextField1").Text;
var item2 = X.GetCmp<TextField>("TextField2").Text;
var item3 = X.GetCmp<TextField>("TextField3").Text;
var item4 = X.GetCmp<RadioGroup>("test").CheckedItems.Count;
X.Msg.Notify("Values", string.Format(tpl, item1, item2, item3, item4)).Show();
}
</script>


<html>
<head>
<title>Ext.NET Example</title>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:Button ID="Button1" runat="server" Text="Create Fields" OnDirectClick="Button1_Click" />
<ext:Button ID="Button2" runat="server" Text="Get Values" OnDirectClick="Button2_Click" />


<ext:FormPanel
ID="FormPanel1"
runat="server"
Title="Example"
DefaultAnchor="100%"
Padding="5"
Height="215"
Width="350"
/>
</form>
</body>
</html>


what am i doing wrong?

Daniil
Oct 10, 2012, 6:08 PM
Hi @trezv,

To get CheckedItems working, there should Items in the RadioGroup. But X.GetCmp<RadioGroup>() can't recreate Items.

We can suggest the following solution.

1. Set GroupName for the RadioGroup.
2. Get a value directly from Request.

Request["groupName"]

Also I would set InputValue for the Radios.

trezv
Oct 10, 2012, 6:27 PM
you're right, it's working now with your suggestions.
thank you.