Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Using a DropDownList on a Web Form

Posted on 2005-03-02
3
Medium Priority
?
241 Views
Last Modified: 2010-04-23
I am new to using VS.net and have a two part question.  First I want to add a combo box control to one of my webforms.  I have noticed that the webform tool box does not have a "combo box" control.  I have tried using the DropDownList to display display the data I want but the following is displayed instead, "System.Data.DataRowView".  First, can I used a dropdownlist to display data on a webform?  Second, if I can, any ideas what i am doing wrong?  Below is the code that I am using to populate the dropdownlist:

Data_Path = "C:\Data\Visual_Studio_Project\Exhibitor_Manager\_Databases\dbExhibitor_Manager.mdb"
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Data_Path & ";User Id=admin;Password=;"
strSQL = "SELECT tblStates.State_Name FROM tblStates ORDER BY tblStates.State_Name;"

Dim cn As New OleDb.OleDbConnection(strConn)
Dim da As New OleDb.OleDbDataAdapter(strSQL, cn)
Dim ds As New DataSet

cn.Open()

da.Fill(ds, "state_name")

Me.DropDownList.DataSource = ds
Me.DropDownList.DataBind()

I am reading the data from an Miscrosoft Access Database.

Thanks for your help.
0
Comment
Question by:Mike_Stevens
  • 2
3 Comments
 
LVL 11

Expert Comment

by:coopzz
ID: 13438376
Heres a snippet that I use all the time to populate a dropdownlist so yes there is a dropdownlist
You will just need to change the dr to the type of dataholder you want to use and fix the getNames to the proper provider.
------------------
    Public Shared Sub bindCBO(ByVal dr As SqlClient.SqlDataReader, ByVal cbo As System.Web.UI.WebControls.DropDownList)
        With cbo
            .DataTextField = dr.GetName(1)
            .DataValueField = dr.GetName(0)
            .DataSource = dr
            .DataBind()
        End With
        dr.Close()
    End Sub
------------------
Cheers

CooPzZ
0
 
LVL 11

Accepted Solution

by:
coopzz earned 500 total points
ID: 13438410
this is the tag that your looking for though.
<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
0
 

Author Comment

by:Mike_Stevens
ID: 13438867
Thanks for the help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Integration Management Part 2
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question