Populate ListBox control from two different tables?

Posted on 2008-11-11
Last Modified: 2012-05-05
Hi, I populate ListBox control from two different tables, the problem that I'm facing is how can I know when I retrieve the items from ListBox which one is belong to a partticular table because ListBox's items only have text and value it cannot take another third parameter that I can use to know if that item belong to a particular table, any suggesstion?
Question by:Abdu_Allah
    LVL 48

    Accepted Solution

    Do you fill the values manually ?
    You can add an extra sign to your value member to identify if belongs to one or another.
    Example, for the ID 123 you can use TA123 and TB123. This way you know that the first two chars identify the table.
    LVL 3

    Author Comment

    Actually I thought about something like that but isn't there any other direct way?
    LVL 3

    Author Comment

    By the way I'm populate them like this:
    lstbx.DataSource = objReader
    lstbx.DataTextField = "item"
    lstbx.DataValueField = "id"
    So I do not think it's possible to add chatacters to the id column unless there is a way to do that in the SQL, here is my SQL statment just in case:

    SELECT [user].user_id AS id,[user].Full_Name AS item FROM [user] UNION SELECT gr.group_id AS id,gr.Name AS item FROM [group] AS gr;

    Open in new window

    LVL 48

    Expert Comment

    You can use another control to do that, like listview or gridivew, and that way you can add an extra column and hide it.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now