Populating DropDownList

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hugh McLaughlin

    #1

    Populating DropDownList

    Hello Everyone and thanks for your help in advance. I am
    developing a class library that reads a SQL Server table
    of names and ID's. I want to populate a dropdownlist with
    the data, however, names in the table may appear more
    than once. I only want to display the name in the
    dropdownlist once. My initial thought wat to create an
    arraylist, then loop through each record, adding a new
    name upon each new name encountered. But I want the name
    to display in the dropdownlist, but the associated value
    to be the IDNumber for the particular name. This would be
    pretty straightforward if I was doing this in a code-
    behind, simply adding to the list as each record was
    read. But since this is a separate class, I have to
    return something that can be bound to the dropdownlist
    control. I am not eactly sure how to go about
    accomplishing this. Any help would be greatly
    appreciated. Thanks.
  • Peter van der Goes

    #2
    Re: Populating DropDownList


    "Hugh McLaughlin" <anonymous@disc ussions.microso ft.com> wrote in message
    news:3de101c3aa a3$9d881c00$a60 1280a@phx.gbl.. .[color=blue]
    > Hello Everyone and thanks for your help in advance. I am
    > developing a class library that reads a SQL Server table
    > of names and ID's. I want to populate a dropdownlist with
    > the data, however, names in the table may appear more
    > than once. I only want to display the name in the
    > dropdownlist once. My initial thought wat to create an
    > arraylist, then loop through each record, adding a new
    > name upon each new name encountered. But I want the name
    > to display in the dropdownlist, but the associated value
    > to be the IDNumber for the particular name. This would be
    > pretty straightforward if I was doing this in a code-
    > behind, simply adding to the list as each record was
    > read. But since this is a separate class, I have to
    > return something that can be bound to the dropdownlist
    > control. I am not eactly sure how to go about
    > accomplishing this. Any help would be greatly
    > appreciated. Thanks.[/color]

    Have you considered creating a query from the table that disallows
    duplicates (allowing SQL to do the dirty work for you), then using the
    results to populate your drop-down list?

    --
    Peter - [MVP - .NET Academic]


    Comment

    • Peter van der Goes

      #3
      Re: Populating DropDownList


      "Hugh McLaughlin" <anonymous@disc ussions.microso ft.com> wrote in message
      news:3de101c3aa a3$9d881c00$a60 1280a@phx.gbl.. .[color=blue]
      > Hello Everyone and thanks for your help in advance. I am
      > developing a class library that reads a SQL Server table
      > of names and ID's. I want to populate a dropdownlist with
      > the data, however, names in the table may appear more
      > than once. I only want to display the name in the
      > dropdownlist once. My initial thought wat to create an
      > arraylist, then loop through each record, adding a new
      > name upon each new name encountered. But I want the name
      > to display in the dropdownlist, but the associated value
      > to be the IDNumber for the particular name. This would be
      > pretty straightforward if I was doing this in a code-
      > behind, simply adding to the list as each record was
      > read. But since this is a separate class, I have to
      > return something that can be bound to the dropdownlist
      > control. I am not eactly sure how to go about
      > accomplishing this. Any help would be greatly
      > appreciated. Thanks.[/color]

      Have you considered creating a query from the table that disallows
      duplicates (allowing SQL to do the dirty work for you), then using the
      results to populate your drop-down list?

      --
      Peter - [MVP - .NET Academic]


      Comment

      Working...