Results 1 to 5 of 5

Thread: Is there a way to create a control array in a form?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2001
    Posts
    33

    Question Is there a way to create a control array in a form?

    I've checked in various places and can't find a reference to this, so I thought I'd post.

    Is there a way to create a 'control array' of sorts on a form so that you don't have to "retype" all the code to create the input box?

    Specifically, I have a listbox on my form that queries our database for values to populate the listbox, as follows:

    Select a Status:
    <select NAME="Status" SIZE="1">
    <%objRS.MoveFirst
    While not objRS.EOF%>
    <option value="<%=objRS("Value")%>"><%=objRS("Value")% ></option>
    <%objRS.MoveNext
    wend
    objRS.close
    %>
    </select>

    This works fine to show one listbox on my form - however, I need to have a specific # (let's say 5) of listboxes that all have the same values from the recordset.

    Is there a way to make something like this an array instead of having to repeat this entire thing for each listbox?

    I'm quite new at this, so any help is much appreciated!! Thanks!

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Think of the output of ASP as a big String.

    When you generate the HTML for the first list, instead of directly writing it to the browser, store it as a string variable, then you can write that string whenever you want to show that list on the page.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2001
    Posts
    33

    Thanks! That works for the items in the list, now what about....

    ...the actual listboxes themselves?

    In other words, for each listbox that I want on the form, do I need to do a seperate control for each one, like:

    <select NAME="Status" SIZE="1">
    <option VALUE.....</option>
    </select>


    <select NAME=="Status" SIZE="1">
    <option VALUE.....</option>
    </select>

    <select NAME=="Status" SIZE="1">
    <option VALUE.....</option>
    </select>



    Or, can I create some kind of control array (structure, whatever), like I can do in VB, as such:

    Dim ctlName As Control
    Set ctlName = Form1.Controls.Add("VB.TextBox", ListArray(Index), Form1)
    ctlName.Visible = True
    ......

    (where array is assigned and indexed in prior portion of code)


    Thanks for any info!

  4. #4
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    2 ways to do this:

    1) Put the code for the Selects inside of a loop (Giving them all the same name has the same effect as a control array). If that won't work for you because they are not all right together (likely) try:

    2) Put the code for the Selects inside of a server side function and call it from the page whereever you want the selects to appear.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2001
    Posts
    33

    Smile Thanks! This all makes sense.

    I'll give it a whirl & see how it goes.

    Much appreciated!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width