How to get checkedItems of RadioGroup/CheckboxGroup during a postback

  1. #1

    How to get checkedItems of RadioGroup/CheckboxGroup during a postback

    I try to use RadioGroup.CheckedItems for getting the checked item from client when it does a postback.

    But I always get count equal to 0, could radiogroup be used this way ?

    or I need use extra parameter to do that ?

    ASPX
      <ext:ResourceManager ID="ResourceManager1" runat="server">
               </ext:ResourceManager>
        <ext:FormPanel ID="FormPanel1" runat="server" ButtonAlign="Right" Height="300" Padding="5"
            Title="Title" Width="300">
           <Content>
             
               <ext:RadioGroup ID="radioGroup01" runat="server">
               </ext:RadioGroup>
               <ext:CheckboxGroup ID="checkboxGroup01" runat="server">
               </ext:CheckboxGroup>
               <ext:Button ID="Button1" runat="server" Text="Submit">
                <DirectEvents>
                    <Click OnEvent="Button1_OnClicked">
                        <EventMask ShowMask="true" MinDelay="100" />
                    </Click>
                </DirectEvents>
               </ext:Button>
               <ext:Label ID="Label1" runat="server">
               </ext:Label>
               <ext:DisplayField ID="DisplayField1" runat="server">
               </ext:DisplayField>
           </Content>
        </ext:FormPanel>
    C# code
     public IList<TestDataItem> DemoDataSource { get; set; }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            DemoDataSource = getDemoData();
    
            if (X.IsAjaxRequest == false)
            {
                initGroup();
            }
    
    
        }
    
        private void initGroup()
        {
            radioGroup01.Vertical = true;
            radioGroup01.ColumnsNumber = 1;
            foreach (TestDataItem item in DemoDataSource)
            {
                Radio radio = new Radio();
                radio.Checked = false;
                radio.InputValue = item.ItemValue;
                radio.BoxLabel = item.ItemText;
                radioGroup01.Items.Add(radio);
    
                Checkbox checkbox = new Checkbox(false, item.ItemText);
                checkbox.InputValue = item.ItemValue;
                checkboxGroup01.Items.Add(checkbox);
            }
        }
    
        protected void Button1_OnClicked(object sender, DirectEventArgs args)
        {
            DisplayField1.Text = "Radio Checked Count:" + radioGroup01.CheckedItems.Count.ToString() + " Checkbox Checked Count:" + checkboxGroup01.CheckedItems.Count.ToString();
        }
    
        // for test
        private IList<TestDataItem> getDemoData()
        {
            IList<TestDataItem> demoDataList = new List<TestDataItem>();
    
            demoDataList.Add(new TestDataItem("XXXX", "0"));
            demoDataList.Add(new TestDataItem("YYYY", "3"));
            demoDataList.Add(new TestDataItem("ZZZZ", "4"));
            return demoDataList;
        }
    
        public class TestDataItem
        {
            public string ItemValue { get; set; }
            public string ItemText { get; set; }
    
            public TestDataItem(string text, string value)
            {
                ItemValue = value;
                ItemText = text;
            }
        }
  2. #2
    Hi,

    You have to recreate items for each request

    protected void Page_Load(object sender, EventArgs e)
       {
           DemoDataSource = getDemoData();
     
           initGroup(); 
     
       }
    Vladimir Shcheglov
    Sr. Developer
  3. #3
    Hi Vladimir:

    thanks for your reply.

    I follow your suggestion, but it doesn't work.

    When button click event invokes, I try to get the count of checked itmes in the event handler.

    Is it a right usage ?
  4. #4
    Hi,

    Please post test sample which can be run locally
    Vladimir Shcheglov
    Sr. Developer
  5. #5
    Hi Vladimir:

    the sample code as following:

    Default.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!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 runat="server">
        <title></title>
    </head>
    <body>
       <ext:ResourceManager ID="ResourceManager1" runat="server">
               </ext:ResourceManager>
        <ext:FormPanel ID="FormPanel1" runat="server" ButtonAlign="Right" Height="300" Padding="5"
            Title="Title" Width="300">
           <Content>
             
               <ext:RadioGroup ID="radioGroup01" runat="server">
               </ext:RadioGroup>
               <ext:CheckboxGroup ID="checkboxGroup01" runat="server">
               </ext:CheckboxGroup>
               <ext:Button ID="Button1" runat="server" Text="Submit">
                <DirectEvents>
                    <Click OnEvent="Button1_OnClicked">
                        <EventMask ShowMask="true" MinDelay="100" />
                    </Click>
                </DirectEvents>
               </ext:Button>
               <ext:Label ID="Label1" runat="server">
               </ext:Label>
               <ext:DisplayField ID="DisplayField1" runat="server">
               </ext:DisplayField>
           </Content>
        </ext:FormPanel>
    </body>
    </html>
    Default.aspx.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    public partial class _Default : System.Web.UI.Page
    {
        public IList<TestDataItem> DemoDataSource { get; set; }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            DemoDataSource = getDemoData();
            initGroup();
        }
    
        private void initGroup()
        {
            radioGroup01.Vertical = true;
            radioGroup01.ColumnsNumber = 1;
            foreach (TestDataItem item in DemoDataSource)
            {
                Radio radio = new Radio();
                radio.Checked = false;
                radio.InputValue = item.ItemValue;
                radio.BoxLabel = item.ItemText;
                radioGroup01.Items.Add(radio);
    
                Checkbox checkbox = new Checkbox(false, item.ItemText);
                checkbox.InputValue = item.ItemValue;
                checkboxGroup01.Items.Add(checkbox);
            }
        }
    
        protected void Button1_OnClicked(object sender, DirectEventArgs args)
        {
            DisplayField1.Text = "Radio Checked Count:" + radioGroup01.CheckedItems.Count.ToString() + " Checkbox Checked Count:" + checkboxGroup01.CheckedItems.Count.ToString();
        }
    
        // for test
        private IList<TestDataItem> getDemoData()
        {
            IList<TestDataItem> demoDataList = new List<TestDataItem>();
    
            demoDataList.Add(new TestDataItem("XXXX", "0"));
            demoDataList.Add(new TestDataItem("YYYY", "3"));
            demoDataList.Add(new TestDataItem("ZZZZ", "4"));
            return demoDataList;
        }
    
        public class TestDataItem
        {
            public string ItemValue { get; set; }
            public string ItemText { get; set; }
    
            public TestDataItem(string text, string value)
            {
                ItemValue = value;
                ItemText = text;
            }
        }
    }
  6. #6
    Hi,

    Please add ASP.NET form and place widgets inside the form
    Vladimir Shcheglov
    Sr. Developer
  7. #7
    Hi

    I try to add ASP.NET from, like
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!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 runat="server">
        <title></title>
    </head>
    <body>
    <form id="testForm" runat="server">
    <div>
        <ext:ResourceManager ID="ResourceManager1" runat="server"></ext:ResourceManager>
        <ext:FormPanel ID="FormPanel1" runat="server" ButtonAlign="Right" Height="300" Padding="5"
            Title="Title" Width="300">
           <Content>  
               <ext:RadioGroup ID="radioGroup01" runat="server">
               </ext:RadioGroup>
               <ext:CheckboxGroup ID="checkboxGroup01" runat="server">
               </ext:CheckboxGroup>
               <ext:Button ID="Button1" runat="server" Text="Submit">
                <DirectEvents>
                    <Click OnEvent="Button1_OnClicked">
                        <EventMask ShowMask="true" MinDelay="100" />
                    </Click>
                </DirectEvents>
               </ext:Button>
               <ext:Label ID="Label1" runat="server">
               </ext:Label>
               <ext:DisplayField ID="DisplayField1" runat="server">
               </ext:DisplayField>
           </Content>
        </ext:FormPanel>
    </div>
    </form>
    </body>
    </html>
    it does not work. Any advise ?
  8. #8
    Hi,

    Please use Items instead Content
    Vladimir Shcheglov
    Sr. Developer
  9. #9
    Thanks ! it could make it work.

    I think I use form panel in wrong way.

    thanks a lot.
  10. #10
    Hi,

    Does <Content> not support checkedItems of radiogroup/checkboxgroup ?

    I need to mix some html tags and ext.net controls in the formpanel, so I take <Content>

    if <Context> not works, the validation will be very difficult to me,

    because I cannot use #{FormPanel}.getForm().isValid() to validate all elements on the panel.

    Does anyone have any advice ?

Similar Threads

  1. [CLOSED] Why i get checkboxgroup.CheckedItems.Count Always 0 ?
    By gs_user in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 23, 2012, 9:42 AM
  2. RadioGroup.CheckedItems.Count == 0 v1.2.0
    By chearner in forum 1.x Help
    Replies: 4
    Last Post: Dec 09, 2011, 2:23 PM
  3. How to Get the RadioGroup.CheckedItems?
    By sk2276699 in forum 1.x Help
    Replies: 1
    Last Post: Jun 28, 2011, 3:22 AM
  4. Replies: 3
    Last Post: Jul 08, 2010, 1:28 PM
  5. [CLOSED] [1.0] RadioGroup CheckedItems empty
    By danielg in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 28, 2010, 5:12 PM

Posting Permissions