Populate ListBox control from two different tables?

Posted on 2008-11-11
Medium Priority
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
  • 2
  • 2
LVL 48

Accepted Solution

jpaulino earned 1500 total points
ID: 22928727
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.

Author Comment

ID: 22929448
Actually I thought about something like that but isn't there any other direct way?

Author Comment

ID: 22929464
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

ID: 22930909
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

840 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