Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 21st, 2005, 05:33 AM
Authorized User
 
Join Date: Dec 2005
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
 
Old December 21st, 2005, 06:25 AM
Friend of Wrox
 
Join Date: Jun 2003
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.
======================================
 
Old December 21st, 2005, 06:39 AM
Friend of Wrox
 
Join Date: Jun 2003
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.
======================================
 
Old December 21st, 2005, 06:41 AM
Authorized User
 
Join Date: Dec 2005
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!!!






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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.