Filling Data into Select List

posted by Scudyen date: Thursday, May 22, 2008 category: ASP

In this short ASP source code, we will pull some data from a database and fill it into a select list. We will create a custom and dynamic output.


Now first we need to connect a database. In this part of oced we prefer to connect MS SQL server. We have a sample database with some data inside.
You could easily modify this connection and use mySQL or MS Access.
<%

    strConnection = "Provider=SQLOLEDB;Server=LOCAL_MS_SQL;User ID=TESTUSER;Password=;Database=glink30;"

%>

Let's play with this connection now. We need a database connection.

<%
    set objConnection = server.creeateobject("adodb.connection")
    objConnection.open strConnection
%>

 Now we have connected to database. We need to get our records from our sample database.

<%
      set objRecords  = objConnection.execute("select catID, categoryName from glink_categories order by catID desc")
       if objRecords.Eof then
            response.write "Sorry, no results !"
       else
%>

We have tested records. If there is no turning records, we will display a custom message to client taht there is no results in query.
<%
    response.write "&nbsp;<SELECT name=catID size=""1""> "
    response.write "<option>Choose Category</option>"
    do while not objRec.eof
    response.write "<option value="""& objRecords("catID") &""">"& objRecords("categoryName") & "</option>" & vbCrlf
    objRecords.Movenext
    loop
    response.write "</select>"
%>

Call this page form your favorite browse (I prefer Mozilla Firefox), you will see that there is a select list contains category names.

Happy Coding !

Read More

Custom Search



Gazatem Technologies Active News Manager


page counter

Listed with 411asp.net Listed with 4aspin.com