473,473 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Get value from dropdownlist

Hi,

I've populated my dropdown list from database (category table) via
datatable. It's showing categories in strings. The problem appears,
when I want to add new record to database (entry_table). I'm using
stored procedures and everything works fine until I want to insert
Category ID into entry_table.

I'm getting the selected item from drop down list:

category = myDropDownList.SelectedItem.Value.ToString

and using Select Case statement I'd like to set up valid ID:

Select Case categoryValue
Case categoryValue = "Economy"
category = 1
Case categoryValue = "Politics"
category = 2
End Select

but, string from dropdownlist contains whitespace. I've tried .Trim
function but it didn't work too. Is there any solution for my problem?
Or is there any other way to get back correct IDs?

Przemek

May 7 '06 #1
2 1965
The value from the dropdownlist contains exactly what you put in it when
you populate it.

What is the data type in the database? If you are using the archaic data
type char instead of varchar, it would be padded with spaces.

The value is not what is displayed in the dropdownlist. Why don't you
put the id in the value instead of the text?

Przemek wrote:
Hi,

I've populated my dropdown list from database (category table) via
datatable. It's showing categories in strings. The problem appears,
when I want to add new record to database (entry_table). I'm using
stored procedures and everything works fine until I want to insert
Category ID into entry_table.

I'm getting the selected item from drop down list:

category = myDropDownList.SelectedItem.Value.ToString

and using Select Case statement I'd like to set up valid ID:

Select Case categoryValue
Case categoryValue = "Economy"
category = 1
Case categoryValue = "Politics"
category = 2
End Select

but, string from dropdownlist contains whitespace. I've tried .Trim
function but it didn't work too. Is there any solution for my problem?
Or is there any other way to get back correct IDs?

Przemek

May 7 '06 #2
populate the dropdown with TEXT and VALUE

TEXT is what the user will read from the dropdownlist
VALUE is the value that you'll retrieve from dropdownlist.selectedvalue

if you do not populate like this, the dropdown value = dropdown text
--

Bruno Alexandre
(a Portuguese in Denmark)

"Przemek" <pr****@gmail.com> escreveu na mensagem
news:11**********************@j73g2000cwa.googlegr oups.com...
Hi,

I've populated my dropdown list from database (category table) via
datatable. It's showing categories in strings. The problem appears,
when I want to add new record to database (entry_table). I'm using
stored procedures and everything works fine until I want to insert
Category ID into entry_table.

I'm getting the selected item from drop down list:

category = myDropDownList.SelectedItem.Value.ToString

and using Select Case statement I'd like to set up valid ID:

Select Case categoryValue
Case categoryValue = "Economy"
category = 1
Case categoryValue = "Politics"
category = 2
End Select

but, string from dropdownlist contains whitespace. I've tried .Trim
function but it didn't work too. Is there any solution for my problem?
Or is there any other way to get back correct IDs?

Przemek

May 7 '06 #3

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

Similar topics

1
by: Antonio D'Ottavio | last post by:
Good morning, I've a problem with a dropdownlist located inside any row of a datalist, I fill both datalist and dropdownlist at runtime, the problem is with the dropdownlist infact using the event...
2
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
3
by: Stephen Adam | last post by:
Hi there, I'm sure i'm missing something really simple here, all i want to do is get the value of the selected item in a list box. Even after much fiddling about last night I still could not get...
6
by: Julius Fenata | last post by:
Dear all, I have created client-side scripting to trigger event onChange from code-behind, like this: DropDownList1.Attributes = "GenerateArticleID()"; At the script on Windows Form, I...
2
by: jason | last post by:
Pardon my ignorance on this. The below code works, except, when I edit a record and update the two drop downs take the first entry in the dropdownlist if not selected. I'd also like the dropdown to...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
1
by: Nathan Sokalski | last post by:
I have a problem that is driving me crazy. I have a User Control composed of three DropDownLists that will be used to select a date. I have everything working except for one thing. When I select a...
6
by: Nathan Sokalski | last post by:
I am writing a User Control that uses 3 DropDownLists. When I attempt to access the SelectedIndex property it incorrectly reports the value selected by the user. Why is this? Here is my code,...
10
by: Dan | last post by:
Hi, I create 5 dropdownlist in code-behind. I want to insert their selectedvalues in a table by making a string separated with ":" I can get their selecedvalues but i'm stuck when i want to...
6
by: Ahmedhussain | last post by:
Hi there, I m doing work on a gridview and Im getting an error: A potentially dangerous Request.Form value was detected from the client (ctl00$Content$GridView1$ctl03$TextBox1="<span...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.