p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ADO.NET (http://p2p.wrox.com/forumdisplay.php?f=109)
-   -   Binding a DataReader To A List Box (http://p2p.wrox.com/showthread.php?t=36322)

testsubject December 21st, 2005 05:33 AM

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

rodmcleay December 21st, 2005 06:25 AM

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.
======================================

rodmcleay December 21st, 2005 06:39 AM

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.
======================================

testsubject December 21st, 2005 06:41 AM

Thanks for the idea.

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

Thanks again!!!



All times are GMT -4. The time now is 08:28 PM.

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