Solved

Dropdownlist control in ASP.NET

Posted on 2004-09-29
2
171 Views
Last Modified: 2010-04-06
Hi all experts.
I have a web form page written in VB.NET and there is a dropdownlist control bound to a datareader on it.
       
        Dim myCommand As OdbcCommand
        Dim myConnection As New OdbcConnection(myConnString)

        myCommand = New OdbcCommand
        myCommand.CommandText = "Select name, email From tblRep Order By name"
        myCommand.Connection = myConnection
        myConnection.Open()
        Me.ddlRep.DataSource = myCommand.ExecuteReader()
        Me.ddlRep.DataTextField = "name"
        Me.ddlRep.DataValueField = "email"
        Me.ddlRep.DataBind()
        myConnection.Close()

Everything looks fine. All data is correctly bound to the dropdownlist. The problem is the page with dropdownlist is designed to display inquiry information summary and administrator opens this page, views the inquiry and finally assigns it to an appropriate personal to handle. But the dropdownlist always displays the first item in the control, so even though the administrator reviewed an inquiry and didn't assign it to any personnel at the moment, the page saves the first person in the control as an assigned rep. Is there a way to bind a control with the first item blank or something like that to prevent unwanted record from being saved.
Thanks
0
Comment
Question by:soweyoung
2 Comments
 
LVL 20

Accepted Solution

by:
ihenry earned 125 total points
ID: 12192922
Try this,

        Me.ddlRep.DataSource = myCommand.ExecuteReader()
        Me.ddlRep.DataTextField = "name"
        Me.ddlRep.DataValueField = "email"
        Me.ddlRep.DataBind()

        Me.ddlRep.Items.Insert( 0, "" )
0
 

Author Comment

by:soweyoung
ID: 12193455
Thanks. That did the trick
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

840 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