Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Data Driven Combo Box


Message #1 by "Drew Dorr" <rootacct@b...> on Mon, 15 Apr 2002 09:24:59
I'm trying to create a data driven combo box. I've found one or two 
scripts on the net, but they're not in .net format and I couldn't get 
them to work anyhow. One in asp.net with vb.net would be preferred.

Basically I want to have one column in a database, say, CarMake display 
in a combo box with each item in the database as it's own selection. I'm 
eventually trying to have something where you select a car make in the 
first box, then a model for the selected make in the box next to that 
one, and based off that, have a list of parts available for that car 
after the Submit button is pressed. 

If you just have something for a combo box being made from a database, 
that would be great - then I can work out how to do the rest, hopefully.

Thanks,

-Drew
Message #2 by "Ken Schaefer" <ken@a...> on Mon, 15 Apr 2002 18:44:25 +1000
You need to:
a) Open a connection to your database
b) Execute a command to retrive the data you want and store it somewhere, eg
a datareader
c) Have an asp:drowndownlist on your page someplace that you can bind to the
datareader.

Here is a simple example (using SQL Server)

<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">

Sub Page_Load
  Dim objSQLConn As SqlConnection
  Dim objSQLCmd As SqlCommand
  Dim objDataReader As SqlDataReader

  objSQLConn = New SqlConnection("Server=***....")

  objSQLCmd = New SqlCommand("Select Field1 FROM Table", objSQLConn)

  objSQLConn.Open()
  objDataReader = objSQLCmd.ExecuteReader()

  cboTest.DataSource = objDataReader
  cboTest.DataBind

  objSQLConn.Close
End Sub
</Script>

<html>
    <body>
        <form runat="server">
            <asp:DropDownList id="cboTest" runat="server" />
        </form>
    </body>
</html>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Drew Dorr" <rootacct@b...>
Subject: [aspx_beginners] Data Driven Combo Box


: I'm trying to create a data driven combo box. I've found one or two
: scripts on the net, but they're not in .net format and I couldn't get
: them to work anyhow. One in asp.net with vb.net would be preferred.
:
: Basically I want to have one column in a database, say, CarMake display
: in a combo box with each item in the database as it's own selection. I'm
: eventually trying to have something where you select a car make in the
: first box, then a model for the selected make in the box next to that
: one, and based off that, have a list of parts available for that car
: after the Submit button is pressed.
:
: If you just have something for a combo box being made from a database,
: that would be great - then I can work out how to do the rest, hopefully.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Message #3 by "Drew" <rootacct@b...> on Tue, 16 Apr 2002 02:29:45 -0400
I don't have access to anything with SQL Server right now. I tried
playing with it to make it work with OLEDB to no avail. Any ideas?

-Drew

-----Original Message-----
From: Ken Schaefer [mailto:ken@a...] 
Sent: Monday, April 15, 2002 4:44 AM
To: aspx_beginners
Subject: [aspx_beginners] Re: Data Driven Combo Box

You need to:
a) Open a connection to your database
b) Execute a command to retrive the data you want and store it
somewhere, eg
a datareader
c) Have an asp:drowndownlist on your page someplace that you can bind to
the
datareader.

Here is a simple example (using SQL Server)

<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">

Sub Page_Load
  Dim objSQLConn As SqlConnection
  Dim objSQLCmd As SqlCommand
  Dim objDataReader As SqlDataReader

  objSQLConn = New SqlConnection("Server=***....")

  objSQLCmd = New SqlCommand("Select Field1 FROM Table", objSQLConn)

  objSQLConn.Open()
  objDataReader = objSQLCmd.ExecuteReader()

  cboTest.DataSource = objDataReader
  cboTest.DataBind

  objSQLConn.Close
End Sub
</Script>

<html>
    <body>
        <form runat="server">
            <asp:DropDownList id="cboTest" runat="server" />
        </form>
    </body>
</html>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Drew Dorr" <rootacct@b...>
Subject: [aspx_beginners] Data Driven Combo Box


: I'm trying to create a data driven combo box. I've found one or two
: scripts on the net, but they're not in .net format and I couldn't get
: them to work anyhow. One in asp.net with vb.net would be preferred.
:
: Basically I want to have one column in a database, say, CarMake
display
: in a combo box with each item in the database as it's own selection.
I'm
: eventually trying to have something where you select a car make in the
: first box, then a model for the selected make in the box next to that
: one, and based off that, have a list of parts available for that car
: after the Submit button is pressed.
:
: If you just have something for a combo box being made from a database,
: that would be great - then I can work out how to do the rest,
hopefully.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





  Return to Index