dynamically adding textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ganesh22
    Banned
    New Member
    • Sep 2007
    • 81

    dynamically adding textbox

    Hi,
    the below code is for dynamically adding textbox, but it will adding for same textbox only my requirement is how many times i click add button such times textbox will add
    for ex: if i click 10 times add button 10 textboxs will add
    [CODE=CPP]
    Session["TextBoxCou nt"] = "3";

    for (int a = 0; a < int.Parse(Sessi on["TextBoxCou nt"].ToString()); a++)
    {
    TableRow tr = new TableRow();
    TableCell tc = new TableCell();
    TextBox tb = new TextBox();

    tb.Attributes.A dd("runat", "Server");
    tb.EnableViewSt ate = false;
    tb.MaxLength = 128;
    tb.ID = "TextBox" + a;

    tc.Controls.Add (tb);
    tr.Cells.Add(tc );
    ctrlTable.Rows. Add(tr);[/CODE]
    Last edited by Frinavale; Apr 22 '08, 01:44 PM. Reason: added [code] tags
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    What error are you getting into this?



    Originally posted by ganesh22
    Hi,
    the below code is for dynamically adding textbox, but it will adding for same textbox only my requirement is how many times i click add button such times textbox will add
    for ex: if i click 10 times add button 10 textboxs will add
    Session["TextBoxCou nt"] = "3";

    for (int a = 0; a < int.Parse(Sessi on["TextBoxCou nt"].ToString()); a++)
    {
    TableRow tr = new TableRow();
    TableCell tc = new TableCell();
    TextBox tb = new TextBox();

    tb.Attributes.A dd("runat", "Server");
    tb.EnableViewSt ate = false;
    tb.MaxLength = 128;
    tb.ID = "TextBox" + a;

    tc.Controls.Add (tb);
    tr.Cells.Add(tc );
    ctrlTable.Rows. Add(tr);

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Are you getting any errors?
      Have you seen this article on how to use dynamic controls in ASP.NET? It has an example on how to dynamically add Textboxes to your web pages.

      -Frinny

      Comment

      Working...