Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dropdownlist control in ASP.NET

Posted on 2004-09-29
2
Medium Priority
?
177 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 375 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

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

886 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