Solved

Dropdownlist control in ASP.NET

Posted on 2004-09-29
2
172 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
How to dynamically load/unload User control in ASP.net page? 2 231
Snap images to the bottom of a div 5 67
Problem to Popup 2 93
Fixed div within Bootstrap carousel item 11 62
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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:

749 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