Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 21st, 2005, 05:33 AM
Authorized User
Points: 285, Level: 5
Points: 285, Level: 5 Points: 285, Level: 5 Points: 285, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: , , .
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default Binding a DataReader To A List Box

Hi folks,

I have a little problem with a datareader and a listbox.

Please see code below

Code:
        If Not Page.IsPostBack Then
            Dim cmdWardList As New Odbc.OdbcCommand("SELECT WARDCODE, WARDNAME FROM ASSETDDH.WARDS5 ORDER BY WARDNAME", cnBarwickPas)
            cnBarwickPas.Open()
            Dim drWardList As Odbc.OdbcDataReader
            drWardList = cmdWardList.ExecuteReader()
            lstWardList.DataSource = drWardList
            lstWardList.DataTextField = "WARDNAME"
            lstWardList.DataValueField = "WARDCODE"
            lstWardList.DataBind()
            drWardList.Close()
            cnBarwickPas.Close()
        End If
Now this is working wonderfully, but the problem is i need to insert an entery into the list box say "Please choose a Ward from the list". So when the page loads the first option you see in the list is above.

Anyone have any ideas??

Thanks
Reply With Quote
  #2 (permalink)  
Old December 21st, 2005, 06:25 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Try,
lstWardList.Items.Add("Please choose a Ward from the list")
*Sytax not tested.
May unfortunately add at the end, but you'd be half way there.
I'll look in to a bit more.

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
Reply With Quote
  #3 (permalink)  
Old December 21st, 2005, 06:39 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Or for the item in the list possition,
lstWardList.Items.Insert(0, "Please choose a Ward from the list")

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
Reply With Quote
  #4 (permalink)  
Old December 21st, 2005, 06:41 AM
Authorized User
Points: 285, Level: 5
Points: 285, Level: 5 Points: 285, Level: 5 Points: 285, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: , , .
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the idea.

Sytax is lstWardList.Items.Insert(0, "Please choose a ward") and works great.

Thanks again!!!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
Binding a combo box to update a list view Amethyst1984 General .NET 0 February 28th, 2006 03:04 PM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM
populating a list box using a DataReader goplayoutside VB Databases Basics 0 April 21st, 2004 07:27 PM
Data list binding Alok Gupta .NET Web Services 0 September 4th, 2003 05:00 AM



All times are GMT -4. The time now is 12:24 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.