?
Solved

Using a DropDownList on a Web Form

Posted on 2005-03-02
3
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

777 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