Problem with text and value properties for dropdownlist bound control

J

Jorge

I have dropdownlist boxes that are bound to a function that loads them. I set the text and value properties with different values as I want the description and the return value to be different. When I select an item the text and value properties are the same, why? example

'*************************************************************************************
'Load the Status Code Drop Down bo
'*************************************************************************************
Private Sub LoadStatusCodeDropDown(

drpStatusSel.DataSource = GetStatusCodeList(
drpStatusSel.DataBind(

End Su

'****************************************************************************************
'This function builds the items available for the Status dropdown boxe
'****************************************************************************************
Public Shared Function GetStatusCodeList() As ListItemCollectio

Dim mobjListBoxData As New ListItemCollection(

With mobjListBoxDat

.Add(New ListItem("Select one...", "None")

.Add(New ListItem("D - Deleted via Extract", "D")
.Add(New ListItem("E - Deleted via WEB", "E")
.Add(New ListItem("H - Hold", "E")
.Add(New ListItem("R - SoftAuto", "R")

End Wit

Return mobjListBoxDat

End Functio

This code from the first item (0)

myString = drpStatusSel.SelectedItem.Valu

is returning: "Select one..." instead of the word "None

Thank
 
M

Mike Moore [MSFT]

Hi,

Please add these lines:
ListBox1.DataTextField = "text"
ListBox1.DataValueField = "value"

As shown in this sample:

Public Sub GetStatusCodeList()
Dim mobjListBoxData As New ListItemCollection
With mobjListBoxData
.Add(New ListItem("Select one...", "None"))
.Add(New ListItem("D - Deleted via Extract", "D"))
.Add(New ListItem("E - Deleted via WEB", "E"))
.Add(New ListItem("H - Hold", "E"))
.Add(New ListItem("R - SoftAuto", "R"))
End With
ListBox1.DataSource = mobjListBoxData
ListBox1.DataTextField = "text"
ListBox1.DataValueField = "value"
ListBox1.DataBind()
End Sub


This made it work on my machine.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
Thread-Topic: Problem with text and value properties for dropdownlist bound control
thread-index: AcOqCzyGb6AGz/zoRgOE4l39vecHxg==
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
From: "=?Utf-8?B?Sm9yZ2U=?=" <[email protected]>
Subject: Problem with text and value properties for dropdownlist bound control
Date: Thu, 13 Nov 2003 09:26:13 -0800
Lines: 43
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
NNTP-Posting-Host: TK2MSFTCMTY1 10.40.1.180
Path: cpmsftngxa06.phx.gbl!cpmsftngxa08.phx.gbl!cpmsftngxa10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet.webcontrols:16149
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols

I have dropdownlist boxes that are bound to a function that loads them. I
set the text and value properties with different values as I want the
description and the return value to be different. When I select an item the
text and value properties are the same, why? example:


'***************************************************************************
***********
'Load the Status Code Drop Down box

'***************************************************************************
***********
Private Sub LoadStatusCodeDropDown()

drpStatusSel.DataSource = GetStatusCodeList()
drpStatusSel.DataBind()

End Sub


'***************************************************************************
**************
'This function builds the items available for the Status dropdown boxe.

'***************************************************************************
**************
Public Shared Function GetStatusCodeList() As ListItemCollection

Dim mobjListBoxData As New ListItemCollection()

With mobjListBoxData

.Add(New ListItem("Select one...", "None"))

.Add(New ListItem("D - Deleted via Extract", "D"))
.Add(New ListItem("E - Deleted via WEB", "E"))
.Add(New ListItem("H - Hold", "E"))
.Add(New ListItem("R - SoftAuto", "R"))

End With

Return mobjListBoxData

End Function


This code from the first item (0):

myString = drpStatusSel.SelectedItem.Value

is returning: "Select one..." instead of the word "None"

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top