listbox datavaluefield and datatextfield

Discussion in 'ASP .Net' started by tshad, May 10, 2005.

  1. tshad

    tshad Guest

    How do I get to the datatextfield of listbox?

    I can get the the datavaluefield using the selectedvalue. I want to get the
    text portion of the listbox that the user selected.

    Thanks,

    Tom
     
    tshad, May 10, 2005
    #1
    1. Advertising

  2. Hi,

    In a list box the user can select single or multiple values. Below is the
    code given for reading the multiple text values of the listbox in a string
    seperated by commas.

    Dim lCtr
    Dim strText as String

    If listBox.Items.Count > 0 Then
    For lCtr = 1 To lstBox.Items.Count
    If istBox.Items(lCtr - 1).Selected = True Then
    strText = lstBox.Items(lCtr - 1).Value
    ' Can have some code to append commas.......


    End If
    Next
    End If

    strText would be a string consistes od comma. You may also use the String
    Builder class, if you want to optimise the string.

    Please let me know if this is what you were looking for.....

    Thanks and Regards,

    Piyush
    "tshad" wrote:

    > How do I get to the datatextfield of listbox?
    >
    > I can get the the datavaluefield using the selectedvalue. I want to get the
    > text portion of the listbox that the user selected.
    >
    > Thanks,
    >
    > Tom
    >
    >
    >
     
    =?Utf-8?B?UGl5dXNoIFRoYWt1cmlh?=, May 10, 2005
    #2
    1. Advertising

  3. Tom try using :-
    " ddlNamesList.SelectedItem.Text"
    e.g ddlNamesList being ur listBox
    Patrick


    "tshad" wrote:

    > How do I get to the datatextfield of listbox?
    >
    > I can get the the datavaluefield using the selectedvalue. I want to get the
    > text portion of the listbox that the user selected.
    >
    > Thanks,
    >
    > Tom
    >
    >
    >
     
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, May 10, 2005
    #3
  4. tshad

    tshad Guest

    "tshad" <> wrote in message
    news:...
    > How do I get to the datatextfield of listbox?
    >
    > I can get the the datavaluefield using the selectedvalue. I want to get

    the
    > text portion of the listbox that the user selected.


    Figured it out.

    listbox.SelectedItem.text

    It is interested that for the value you can use either:

    listbox.SelectedValue or listbox.SelectedItem.Value

    I'm surprised that there isn't a listbox.SelectedText also (to be
    consistant).

    Tom
    >
    > Thanks,
    >
    > Tom
    >
    >
     
    tshad, May 10, 2005
    #4
    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. Parodi Development
    Replies:
    0
    Views:
    3,667
    Parodi Development
    Sep 10, 2004
  2. Sam
    Replies:
    1
    Views:
    12,084
    Eliyahu Goldin
    Feb 18, 2005
  3. Gerald

    Listbox DataValueField

    Gerald, Jun 22, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    737
    Gerald
    Jun 22, 2005
  4. l7alabeh
    Replies:
    4
    Views:
    2,624
    l7alabeh
    Sep 20, 2006
  5. Gerald

    Listbox DataValueField

    Gerald, Jun 23, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    153
    Gerald
    Jun 23, 2005
Loading...

Share This Page