Create a list of multiple column options with ASP

Source: Internet
Author: User
Tags array contains empty include connect
Creating concepts
Author: Green Apple studios This article hits: 4755

Original source:


First, we need to highlight some concepts to give you some of the elements that make this "miracle" happen. Too easy to divulge the foreshadowing is not a good form for storytelling, so those who do not want to see the end in the first place should walk away.

The first part of this complex is the use of fixed-width fonts. The two standard fixed-width fonts for Internet Explorer and Netscape are Courier new and Lucida Console respectively. Most web designs don't use standard fonts entirely, but they are a necessary condition for this particular technical work, and they look good as shown in the two images above.

To explain further, a fixed-width font is a font, and all characters of this font say that each character occupies the same space. So you might want to take some steps to make sure that one or the other of these fixed-width fonts is already installed on the client that makes up your target audience. If you want to use your browser to see if these fonts are currently installed, IE5 to Tools | Under Internet Options, click the Fonts button on the General tab of the Internet Options window. You will see a region called Plain Text font:


This is the list of all the fixed-width fonts currently installed. For Netscape 4 and later, to edit | Preferences, expand the appearance in Tree-view and select Fonts. There is a drop-down list of fixed Width fonts.

The second part is the ability to apply a particular font to the list of options. In IE4 and above versions, you can request a font in the following ways:

< SELECT name= "Myselect" Style=font-family:lucida Console, Courier New; >

For Netscape, you can use the font tag around the list of options:

< FONT face= "Lucida Console, Courier New" ></font >

The third part is the use of uninterrupted space &nbsp and pipe characters.

In the next section I'll show you an example of a simple, fully coded list of multiple options. The last section will demonstrate a multiple-option list function that uses database calls in the context and will explore some possible parameter selections.

Basic list of multiple column options
Author: Green Apple studios This article hits: 4755

The following HTML example demonstrates the most basic form of a list of multiple columns options:

< HTML >
< head >
< TITLE >simple multi-column Select list</title >

< BODY >
< FORM >
< FONT face= "Lucida Console, Courier New" >
< SELECT name= "Sel1" size=3 style= "height:65 px; width:350px;
Font-family:lucida Console, Courier New; Font-size:x-small; ">
< OPTION value= "1" >
John | Chips |
Intel | Hillsboro
< OPTION value= "2" >
Sue | Wotz |
Microsoft | Redmond
< OPTION value= "3" >
Nathan | Babb |
Eprise | Framingham
</select >
</font >
</form >
</body >

List options include FirstName, LastName, Company, and City. In order to properly format the first column, we must find the name ' Nathan ' with the largest number of bytes, and then add a nonbreaking space for all 7 characters. Then we add the appropriate number of spaces to John and Sue, make it 7 characters, add the pipe symbol at the end, and now we have a formatted column.

Note that we added the < FONT > tag to the above code. This is to be considered for use in Netscape, because Netscape does not recognize font attributes like ie. Also note the appearance of < FORM > tags. This is Netscape's request. IE allows you to draw form fields, list of options, etc. without placing them in < form > tags, but in Netscape, if you want to extract form control, you need the form's markup.


There are obvious flaws in using this method. For example, it is not easy to add a record to the list, especially if it is not the right size and the space that the encoding determines. In addition, this type of list is difficult to maintain, especially if you are not the person who created the code. In the next section I'll show you how to create a list of multiple column options dynamically using code.

Expanded multi-column options list (i)
Author: Green Apple studios This article hits: 4755

The list of multiple-column options I'm performing is a function called Aspoptionlistmulti (). If you want to skip the explanation and go directly to the Code section, you can find the function to download at the end of the article. The downloaded function contains the following files:

Simpleselect.htm is the code for the first example above. My dynamic example uses a database that is access and its data source is Multicolumnlist.mdb. You can see the actual execution of this dynamic example by running the example.asp script. This file contains to establish a connection to the database, aspfunction.asp a function call to Aspoptionlistmulti ().

As listed in the following table, my multiple-column list function has 10 parameters. I don't want to spend more time on aspoptionlistmulti () data recovery. In the next discussion, assuming that there is some type of data source, you will handle the returned rows in the function. In this example, I assume that the program I'm storing has no parameters. I also no longer explain how this function is invoked. If you want to know how the function is invoked, you can refer to the example at the download point.

Proc-Generate Stored Program names
Parmname-optional parameter names for SP calls (can pass a single value or array)
Parmval-optional parameter values for SP calls (can pass a single value or array)
Val-value bar for list of options
Selval-If it is an empty string, it is not selected. If it is in the list of options, it is passed as the selected value.
Column-Represents an array of columns in the list of options.
Maxcollen-the maximum possible length of a column. -1 off. Can be a single value, for multiple columns is an array.
Name-the names of the list of options.
Firstopt-Determines whether the first option is empty. If it is "|*" then there is no option. If a value is passed, it is the value of the first option (0 or 1 is recommended).
Style-the font must be a fixed length (Courier New or Lucida Console). Parameter selections for other fonts can also be passed.
Optattr-you might want to include a selection of properties (full references) in the list of options (such as function calls, properties, and so on).
Size-1 is normal, 2 or more are multiple selections (rows).
The following code is a function declaration and its other arguments.

Function Aspoptionlistmulti (proc, Parmname, Parmval, Val, selval, column, Maxcollen, name, firstopt, style, optattr, size)

On Error Resume Next

For our particular case, you may want to include an on Error Resume Next statement at the very beginning of the function. Placing this statement in code allows the code to continue executing in the event of an error (perhaps in the returned recordset, where the code encounters an unexpected value in a row). There is this statement in the code and you can also create the contents of the list of options. The disadvantage is that in the event of an error, your application user will not be able to report the error directly to you, perhaps this error will lead to the next error, make your debugging work more difficult.

The next important part of the code is a simple test of the browser type. When we finally set up the list of options, we need to differentiate between IE and Netscape, because both of them have different handling of the list of options when specifying the font and model. For the sake of simplicity, I will not delve into the browser compatibility code, because I would also like to focus on the key concepts of the code. If you want to know more about compatibility issues, you can refer to the code provided at the end of this article.

Strua = Request.ServerVariables ("Http_user_agent")
If Instr (Strua, "MSIE") Then
BrowserType = "IE"
End If

The next step is to call the database to restore the recordset that we want to use when we create the multiple-column list. The variable rsselect contains the returned set result. I implemented a call to the database through a DCOM object spserverobj, passing parameters and their values in the array. However, it is also simple to use ADO to make calls through ASP, in this case, a simple selection statement to restore the recordset.
Set Rsselect =

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.