How to dynamically show Checkboxes using C#?

  1. #1

    How to dynamically show Checkboxes using C#?

    I wanna show some checkboxes in my Asp.net page
    but when running the page is blank .
    Are there some wrong in the following code:
    <%@ Page Language="C#" AutoEventWireup="true" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <script runat="server">
        public string outstr;
        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            int count = 10;
            for (int i = 0; i < count; i++)
                sb.Append("<ext:Checkbox ID='").Append(i).Append("'").Append(" runat='server' AutoWidth='true' />");
            outstr = sb.ToString();
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>hello</title>
    </head>
    <body>
        <form id="form1" runat="server">
        
         <ext:ScriptManager ID="ScriptManager1" runat="server"/>
        
         <% = outstr %>
           
        
    
        </form>
    </body>
    </html>
  2. #2

    RE: How to dynamically show Checkboxes using C#?

    Hi lei,

    You can create server-side Controls and add them to the .Controls Collection of the Page, or another Control.

    The following sample reproduces your original sample using server controls.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Collections.Generic" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                this.Form.Controls.Add(new Ext.Net.Checkbox { 
                    FieldLabel = "Checkbox " + i.ToString() 
                });
            }
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html>
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
        </form>
    </body>
    </html>
    Hope this helps

    Geoffrey McGill
    Founder
  3. #3

    RE: How to dynamically show Checkboxes using C#?

    thanks a lot
    it is very helpful
    i should have realised that coolite controls are essentially Asp.net server-side controls
  4. #4

    RE: How to dynamically show Checkboxes using C#?

    No problem.


    ...that coolite controls are essentially Asp.net server-side controls
    Not essentially. They are ASP.NET web controls.


    Geoffrey McGill
    Founder
  5. #5
    Quote Originally Posted by lei View Post
    I wanna show some checkboxes in my Asp.net page
    but when running the page is blank .
    Are there some wrong in the following code:
    <%@ Page Language="C#" AutoEventWireup="true" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <script runat="server">
        public string outstr;
        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            int count = 10;
            for (int i = 0; i < count; i++)
                sb.Append("<ext:Checkbox ID='").Append(i).Append("'").Append(" runat='server' AutoWidth='true' />");
            outstr = sb.ToString();
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>hello</title>
    </head>
    <body>
        <form id="form1" runat="server">
        
         <ext:ScriptManager ID="ScriptManager1" runat="server"/>
        
         <% = outstr %>
           
        
    
        </form>
    </body>
    </html>
    You can geberate controls dynamically . try this http://csharp.net-informations.com/g...ontrols-cs.htm , you can set properties to each controls individually.

    zene.

Similar Threads

  1. Replies: 5
    Last Post: May 23, 2013, 3:32 PM
  2. [CLOSED] CheckboxGroup, adding checkboxes dynamically and viewstate
    By Edward in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Mar 09, 2011, 6:43 PM
  3. [CLOSED] Treepanel Checkboxes
    By dheeraj_us in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Aug 12, 2010, 6:59 PM
  4. Replies: 1
    Last Post: Mar 12, 2010, 9:36 AM
  5. [CLOSED] Checkboxes in CheckBoxGroup
    By methode in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 11, 2009, 3:27 PM

Posting Permissions