NEWBIE - Multicolumn Listbox populated from SQL statement

Discussion in 'ASP .Net' started by RockNRoll, Aug 4, 2004.

  1. RockNRoll

    RockNRoll Guest

    Greetings,

    I am attempting to generate a multicolumn listbox from a SQL statement in
    ASP.NET. Below is my SQL Statement:

    SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]

    I would like a two column list box with [PACONTNUMBER] on the left and
    [PAcontname] on the right. I can do this in MS Access with no problem, but
    I do not know to get my datareader info into a multicolumn listbox. I can
    do one column of data just fine, but cannot add the second column.

    Thank you for your help,

    -Dave
    RockNRoll, Aug 4, 2004
    #1
    1. Advertising

  2. Declare the listbox on the .aspx page:
    <asp:ListBox runat="server" id="LB" />

    Then in code-behind, add the items as you iterate through the repeater:
    'Get Repeater 'Data'...
    While ( Data.Read() )
    LB.Items.Add(New ListItem(Data.Item("Field1") + "-" + Data.Item("Field2"), Data.Item("Field1")))
    End While

    Note: The above code will have [Field1-Field2] as the text field and [Field1] as the value field for each item in the SqlDataReader

    "RockNRoll" wrote:

    > Greetings,
    >
    > I am attempting to generate a multicolumn listbox from a SQL statement in
    > ASP.NET. Below is my SQL Statement:
    >
    > SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
    >
    > I would like a two column list box with [PACONTNUMBER] on the left and
    > [PAcontname] on the right. I can do this in MS Access with no problem, but
    > I do not know to get my datareader info into a multicolumn listbox. I can
    > do one column of data just fine, but cannot add the second column.
    >
    > Thank you for your help,
    >
    > -Dave
    >
    >
    >
    =?Utf-8?B?UnlhbiBSaWRkZWxs?=, Aug 4, 2004
    #2
    1. Advertising

  3. RockNRoll

    Raterus Guest

    concatenate two columns into one in your sql query

    select column1 + column2 as multicolumn
    from mytable

    then have your datareader use "multicolumn" as your textfield. You'll probably have to do some spacing on top of this if you want the results in actual columns, but that should be easy enough.

    Also there is a third party control that does multi-column listbox and some more stuff
    http://easylistbox.com/demoQuickStart.aspx#easy

    --Michael

    "RockNRoll" <> wrote in message news:...
    > Greetings,
    >
    > I am attempting to generate a multicolumn listbox from a SQL statement in
    > ASP.NET. Below is my SQL Statement:
    >
    > SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
    >
    > I would like a two column list box with [PACONTNUMBER] on the left and
    > [PAcontname] on the right. I can do this in MS Access with no problem, but
    > I do not know to get my datareader info into a multicolumn listbox. I can
    > do one column of data just fine, but cannot add the second column.
    >
    > Thank you for your help,
    >
    > -Dave
    >
    >
    Raterus, Aug 4, 2004
    #3
    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. kackson
    Replies:
    4
    Views:
    2,883
    Eliyahu Goldin
    Nov 30, 2004
  2. Adam Clauss

    Multicolumn tree view control

    Adam Clauss, Apr 6, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    8,388
    belgaard
    Sep 23, 2006
  3. Laxmi
    Replies:
    4
    Views:
    5,449
    Laxmi
    Jan 2, 2004
  4. Dessip
    Replies:
    1
    Views:
    578
    Dessip
    Jul 5, 2006
  5. John Kotuby
    Replies:
    1
    Views:
    616
    bruce barker
    Mar 12, 2008
Loading...

Share This Page