-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: nitin_karan
Message 4 in Discussion

Hi Smithesh,   First add a placeholder (design time) and then do the following.   
Sample   <form runat="server">
    How many TextBoxes would you like to create?
    <asp:textbox runat="Server" id="txt1" Columns="3" />     <br />
    <asp:button runat="server" Text="Create Dynamic TextBoxes"
           OnClick="CreateTextBoxes" />     <p>
    <asp:PlaceHolder runat="server" id="TextBoxesHere" />
</form>   Then use the following segment in the button click   void 
CreateTextBoxes(Object sender, EventArgs e)
{ 
  int n = Int32.Parse(txtTBCount.Text);
      
  // now, create n TextBoxes, adding them to the PlaceHolder TextBoxesHere
  for (int i = 0; i < n; i++)
  {
    TextBoxesHere.Controls.Add(new TextBox());
  }
      
  // now, set the Text property of each TextBox
  IterateThroughChildren(this);
}   Then to Access the Control, you can do something like this.   void 
IterateThroughChildren(Control parent)
{
  foreach (Control c in parent.Controls)
  {
    if (c.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox")
          && c.ID == null)
    {
      // ...do something...
    }
        
    if (c.Controls.Count > 0)
    {          
      IterateThroughChildren(c);          
    }
  }
}
   I think this should help you. However i would like to suggest you somethings. Do 
you have a knowledge of Repeater Control, this particular control is very helpful in 
implementing in adding controls.   If what you're creating dynamically repeats based 
on some kind of loop, either from a database, an array, the file system, or similar, 
again you don't need to use dynamic controls.  This is where a Repeater comes in 
handy.  You can use a Repeater to repeat just about anything, including repeating a 
Datagrid for every row in a database table, for example.
 --Nitin

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to