470,849 Members | 1,175 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

dynamilaccy created textboxs

Hi
Iam using below code for creating dynamically textboxs bt the below code is creating only one vertical row for textboxs now i want 3 vertical rows can u give a code??

Expand|Select|Wrap|Line Numbers
  1. using System.Collections.Generic;
  2.  
  3. public partial class _Default : System.Web.UI.Page
  4. {
  5.    int controlCounter = 0;
  6.    List<string> myControlList;
  7.  
  8.    protected override void LoadViewState(object savedState)
  9.    {
  10.       base.LoadViewState(savedState);
  11.       myControlList = (List<string>)ViewState["myControlList"];
  12.       foreach (string ctlID in myControlList)
  13.       {
  14.          controlCounter++;
  15.          TextBox box = new TextBox();
  16.          box.ID = ctlID;
  17.          LiteralControl lineBreak = new LiteralControl("<br />");
  18.          controlHolder.Controls.Add(box);
  19.          controlHolder.Controls.Add(lineBreak);
  20.       }
  21.    }
  22.  
  23.    protected void Page_Load(object sender, EventArgs e)
  24.    {
  25.       if (!IsPostBack)
  26.       {
  27.          myControlList = new List<string>();
  28.          ViewState["myControlList"] = myControlList;
  29.       }
  30.    }
  31.  
  32.    protected void addControlButton_Click(object sender, EventArgs e)
  33.    {
  34.       controlCounter++;
  35.       TextBox box = new TextBox();
  36.       box.Text = "a new text Box";
  37.       box.ID = "textBox" + controlCounter.ToString();
  38.       LiteralControl lineBreak = new LiteralControl("<br />");
  39.       controlHolder.Controls.Add(box);
  40.       controlHolder.Controls.Add(lineBreak);
  41.       myControlList.Add(box.ID);
  42.       ViewState["myControlList"] = myControlList;
  43.    }
  44. }
May 16 '08 #1
0 792

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Tushar | last post: by
3 posts views Thread by Happy Man | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.