Basic dynamic repeating form element in ASP.NET2.0?

Discussion in 'ASP .Net' started by mj.redfox.mj, Apr 26, 2007.

  1. mj.redfox.mj

    mj.redfox.mj Guest

    Does anyone know how I can do the following sort of thing (written in
    classic ASP), but in ASP.NET?

    This is a very, very basic repeating form element which uses a counter
    'cntItems' to hold the current selected number of repeats:

    <% for intCounter = 1 to cntItems %>

    <input type="text" name="txtInput<% =intCounter %>">

    <% next %>

    This would create a list of textboxes named 'txtInput1' through to
    e.g. 'txtInput8' if the value of cntItems happens to be 8. I just
    can't seem to find any examples of this being done in .NET, any advice
    much appreciated!

    Thanks, Mark
    mj.redfox.mj, Apr 26, 2007
    1. Advertisements

  2. mj.redfox.mj

    David Guest

    something along the lines of...

    TextBox tb;
    for (count = 1; count <= cntItems; count++)
    tb = new TextBox();
    tb.ID = "txtInput" + count.ToString();
    Page.Controls.Add(new LiteralControl("<br/>");

    Best regards,
    Dave Colliver.
    ~~ - Local franchises available
    David, Apr 26, 2007
    1. Advertisements

  3. mj.redfox.mj

    mj.redfox.mj Guest

    Many thanks Dave, appreciated.

    mj.redfox.mj, Apr 27, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.