[CLOSED] Dynamic Creation of Radio Buttons within Radio Group

  1. #1

    [CLOSED] Dynamic Creation of Radio Buttons within Radio Group

    Hi,


    Is there any way to programmatically create radio buttons within a radio group? Ideally I'd like to do this via a store (each row being a radio button within the Radio Group), but that doesn't appear to be an option.


    I've also tried to add via code:


    <ext:RadioGroup  ID="radioGroup1" runat="server">
    </ext:RadioGroup>
    In C# :


    Radio radio = new Radio();
    radio.Value = 1000;
    radio.FieldLabel = "Test";
    radio.ID = "radio1";
    radioGroup1.Items.Add(radio);
    Any ideas?


    Cheers


    Steve
    Last edited by Daniil; Apr 09, 2011 at 12:58 PM. Reason: [CLOSED]
  2. #2

    RE: Dynamic Creation of Radio Buttons within Radio Group

    *Hi Guys,

    Did I ask something really obvious, which the toolkit already does?


    Cheers


    Steve
  3. #3

    RE: Dynamic Creation of Radio Buttons within Radio Group

    Hi Steve,

    Please see the following sample which adds Radio programatically (please update from SVN first, we have fixed bug when single Radio in RadioGroup). Please note that adding Radio to the group is impossible during AjaxEvent

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            Radio radio = new Radio();
            radio.Value = 1000;
            radio.BoxLabel = "Test";
            radio.ID = "radio1";
            radioGroup1.Items.Add(radio);
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <ext:RadioGroup  ID="radioGroup1" runat="server">
            </ext:RadioGroup>
        </form>
    </body>
    </html>

  4. #4

    RE: Dynamic Creation of Radio Buttons within Radio Group

    Hi Vlad,

    I'm afraid I can't get this to work. Here's the code (datatable just holds two columns, id and fieldValue):

    DataTable influencerValues = HostConfig.getFieldValues("influencer");
    
    foreach(DataRow dr in influencerValues.Rows)
    {
        Radio radio = new Radio();
        radio.Value = dr["fieldValue"].ToString();
        radio.BoxLabel = "influencerGroup";
        radio.ID = dr["id"].ToString();
        influencerRadioGroup.Items.Add(radio);
    }
    Here's the markup:


    <ext:FormLayout ID="contactFL" runat="server">
        <ext:Anchor>
            <ext:RadioGroup ID="influencerRadioGroup" runat="server">
            </ext:RadioGroup>  
        </ext:Anchor>
    </ext:FormLayout>
    When loading in the browser, I get :

    Line 1982
    Error: 'this.items.0' is null or not an object
    Any ideas?

    Cheers

    Steve
  5. #5

    RE: Dynamic Creation of Radio Buttons within Radio Group

    Hi Steve,

    Did you update from SVN? Does my example work for you?
    *
  6. #6

    RE: Dynamic Creation of Radio Buttons within Radio Group

    *Hi Vlad,

    *I did get your example to populate the radio buttons in the end, which is great. Thank you.


    My only issue now is that I can't detect which radio button is selected on submitting back to the server.


    For example, I*created*a radio group with a single static radio button. I then*programatically*added 2 other radio button. On calling an AjaxMethod, only the static radio button is seen within the radio group. The programmatically added radio buttons are not submitted back.


    Any ideas on how to fix this?


    Cheers


    Steve
  7. #7

    RE: Dynamic Creation of Radio Buttons within Radio Group

    Hi,

    Please note that you must recreate dynamic controls on each request
    Please see the following sample
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic"%>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            Radio radio2 = new Radio{ID = "Radio2", BoxLabel = "Radio2"};
            Radio radio3 = new Radio { ID = "Radio3", BoxLabel = "Radio3" };
            
            RadioGroup1.Items.Add(radio2);
            RadioGroup1.Items.Add(radio3);
        }
        
        [AjaxMethod]
        public void AjaxMethod1()
        {
            List<Radio> radios = RadioGroup1.CheckedItems;
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>    
        <form id="form1" runat="server">
            <ext:ScriptManager runat="server"></ext:ScriptManager>
            
            <ext:RadioGroup ID="RadioGroup1" runat="server">
                <Items>
                    <ext:Radio ID="Radio1" runat="server" BoxLabel="Radio1"></ext:Radio>
                </Items>
            </ext:RadioGroup>
            
            <ext:Button runat="server" Text="Call ajax method">
                <Listeners>
                    <Click Handler="Coolite.AjaxMethods.AjaxMethod1();" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>

Similar Threads

  1. Retrieve checked radio from Radio Group
    By ttharaka2002 in forum 1.x Help
    Replies: 0
    Last Post: Mar 25, 2010, 2:15 AM
  2. [CLOSED] [1.0] Radio buttons that appear as buttons
    By MP in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Mar 24, 2010, 6:28 PM
  3. radio group setvalue
    By [WP]joju in forum 1.x Help
    Replies: 1
    Last Post: Jan 11, 2010, 4:35 AM
  4. using image with radio buttons
    By pearl in forum 1.x Help
    Replies: 0
    Last Post: May 23, 2009, 5:09 AM
  5. Radio Group
    By amitpareek in forum 1.x Legacy Premium Help
    Replies: 0
    Last Post: Dec 04, 2008, 5:06 PM

Posting Permissions