?
Solved

VB.net store/select values in multiline listbox based on DB tables.

Posted on 2007-03-22
4
Medium Priority
?
1,033 Views
Last Modified: 2010-05-18
Hi,

I have a pretty simple VB.net page displaying a logged in user's preferences that I am trying to add a new control to. I'm adding a multi line listbox which loads a list of countries from a table (lets say tblCountry). This table contains reference data of country names and country IDs.

However, when this listbox is loaded, I want it to select countries based on the current user's "preferred countries". Which means I need to store the user's selected countries in a different table somewhere - not the tblCountry table.

I have no problems loading the country list from tblCountry and binding it to the listbox but I can't work out how to also load and store the selected countries into another table and update the selected values of the multiline listbox on this user preferences page.

Any ideas?
0
Comment
Question by:bradderick
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
jef06 earned 1500 total points
ID: 18778032
You can do an LEFT OUTER JOIN with this other table, and if the value is null it means that the user does not have selected anything otherwise you have the value previously selected.
0
 

Author Comment

by:bradderick
ID: 18778050
Okay that sounds like it would work. But how to set the Selected property for the appropriate countries in the listbox then?

Currently the DataTextField property is set to the field  "CountryName" and DataValueField property is set to "iCountryID" before the databind.

How do I set the selected items based on the outerjoin you mentioned?
0
 
LVL 5

Expert Comment

by:jef06
ID: 18778063
If you can select multiple countries use the left outer join and use LisItem and for each element check if there is a value, but it looks like you can select only one country in your case, it might be better to create a method that return the country selected and you set the SelectedIndex in looping threw your values.
0
 

Author Comment

by:bradderick
ID: 18783685
No actually you were right in the first place - the user can select multiple countries. Can you wlaborate a little more about the listitem method?

Any example code would be excellent!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) 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.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

764 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