Problem with text and value properties for dropdownlist bound control

Discussion in 'ASP .Net Web Controls' started by Jorge, Nov 13, 2003.

  1. Jorge

    Jorge Guest

    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
    Jorge, Nov 13, 2003
    #1
    1. Advertising

  2. 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=?=" <>
    > Subject: Problem with text and value properties for dropdownlist bound

    control
    > Date: Thu, 13 Nov 2003 09:26:13 -0800
    > Lines: 43
    > Message-ID: <>
    > 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

    >
    Mike Moore [MSFT], Nov 13, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sunil panda

    Lower bound & Upper bound

    sunil panda, Dec 25, 2003, in forum: Java
    Replies:
    9
    Views:
    7,212
    thushara wijeratna
    Oct 7, 2008
  2. Rhiner Dan
    Replies:
    1
    Views:
    738
    Mike Wahler
    Mar 27, 2005
  3. Mario Krsnic
    Replies:
    0
    Views:
    367
    Mario Krsnic
    Jun 23, 2006
  4. Phillip Vong
    Replies:
    0
    Views:
    410
    Phillip Vong
    Jul 27, 2006
  5. anyeone
    Replies:
    6
    Views:
    228
    Phillip Williams
    Dec 21, 2005
Loading...

Share This Page