473,388 Members | 1,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How do I set the asp:listbox value from a database?

Suppose I have a listbox with 4 values: VISA, MC, DISCOVER, AMEX.
I read a value out of a database as follows:
myReader("CreditCardType")
Now I want to set the listbox selection to the value in the database.
Do I have to loop through every line of the listbox until I find one
that matches?
Or is there an easier way?
I tried
CreditCardType.SelectedItem.Value = myReader("CreditCardType")
but that gives me an error message
Thanks,
Marvin

Nov 19 '05 #1
1 1082
CreditCardType.Items.FindByValue(myReader("CreditC ardType")).Selected =
true;

"COHENMARVIN" <co*********@hotmail.com> wrote in message
news:11********************@g49g2000cwa.googlegrou ps.com...
Suppose I have a listbox with 4 values: VISA, MC, DISCOVER, AMEX.
I read a value out of a database as follows:
myReader("CreditCardType")
Now I want to set the listbox selection to the value in the database.
Do I have to loop through every line of the listbox until I find one
that matches?
Or is there an easier way?
I tried
CreditCardType.SelectedItem.Value = myReader("CreditCardType")
but that gives me an error message
Thanks,
Marvin

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Richard Fennell | last post by:
I am trying to use asp:listbox on a form, when a user selects a row in the asp:listbox a panel is displayed on the centre of the screen with a message, a bit like a model dialog on the form. The...
0
by: John Giblin | last post by:
I have a ListBox within a repeater tag and I am trying to set the selected value. I tried the following without success. I was also tryng to make a method for the selectedindex but I do not know...
1
by: Ray Valenti | last post by:
I have a ASP listbox that I am trying to populate with two fields, one for display (Category) and one to store (ID) as the selected item. I can successfully populate and view the list. How ever...
1
by: Daniel | last post by:
hi, I had an asp:listbox, and everytime i click item inside, the bar automatically go to the top, is there any way to keep the scroll position? I turn on the smartNavigation, it still doesn't...
2
by: Dan Nash | last post by:
Hi again! Right, okay... im now trying to get the value of an <asp:TextBox> control. so I have on my ASPX page... <asp:ListBox id="results" runat="server"></asp:ListBox> <asp:TextBox...
2
by: Simon Prince | last post by:
Help I have a ASP:Listbox on a form. My page Adds items to this this via Client-Side Script only. Such as... var vObj_TargetElement =...
3
by: Ryan Taylor | last post by:
Hello. I have an application where I need the user to be able to add items to a listbox. I've implemented this via javascript. The listbox is an <asp:ListBox>. However, when the user submits the...
5
by: Chris Kettenbach | last post by:
Good morning, Does anyone happen to know if there's a way to make an array of the selected items in an asp:ListBox? I know you can loop through and check the selected property, my question is how...
2
by: Mark Rae | last post by:
Hi, Looking for some advice again... Imagine two ListBox controls denoting something like students and team membership e.g. many students can be members of many teams (e.g. the hockey team,...
7
by: mikeh3275 | last post by:
I'm creating a .net program that uploads images to the FTP server. A blank listbox is populated dynamically on the client side from the value of the html input file widget. There is also a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.