473,405 Members | 2,261 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,405 software developers and data experts.

Access DropDownlist datavaluefield value

Hello Group,
As far as a dropdownlist, is there a way to access both values for
the datatextfield (like a name, etc) AND the value of the datavaluefield
(like a record number, or index etc).

the dropdown list is populated by a query to a datbase table.
loaded with a datareader like below:

Dlist.DataSource = myCommand.ExecuteReader();
Dlist.DataTextField = TextField; (this would be a name, "Jones Inc.")
Dlist.DataValueField = ValueField; ("CustID", the value of which
is a number like 101, etc)
Dlist.DataBind();

I am using c#, and a dropdown component. It show the name just fine,
but I have not yet seen how to get the customer id associated with the
name (the number is a primary key). I can do it by concatenating two
values from the table like "14 Jones Inc." and then dividing the string
at the space char. I would like to have the dropdown show the only
name, and be able to access the customer id as well.

I have not yet seen how (or if) this can be done with a webcontrol and
web form in .net.

Any tips would be helpful,

Thanks,

eric
Jan 1 '06 #1
1 7398

There are three values you can access for a dropdownlist:

ddlControl.SelectedIndex; // int
ddlControl.SelectedValue; // string
ddlControl.SelectedItem.Text; // string

If value of ddl, like CustID, is integer type, you need convert it:

int CustID = Convert.Toint32(ddlControl.SelectedValue);

HTH

Elton Wang
"Eric W. Holzapfel" wrote:
Hello Group,
As far as a dropdownlist, is there a way to access both values for
the datatextfield (like a name, etc) AND the value of the datavaluefield
(like a record number, or index etc).

the dropdown list is populated by a query to a datbase table.
loaded with a datareader like below:

Dlist.DataSource = myCommand.ExecuteReader();
Dlist.DataTextField = TextField; (this would be a name, "Jones Inc.")
Dlist.DataValueField = ValueField; ("CustID", the value of which
is a number like 101, etc)
Dlist.DataBind();

I am using c#, and a dropdown component. It show the name just fine,
but I have not yet seen how to get the customer id associated with the
name (the number is a primary key). I can do it by concatenating two
values from the table like "14 Jones Inc." and then dividing the string
at the space char. I would like to have the dropdown show the only
name, and be able to access the customer id as well.

I have not yet seen how (or if) this can be done with a webcontrol and
web form in .net.

Any tips would be helpful,

Thanks,

eric

Jan 1 '06 #2

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

Similar topics

12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
6
by: Sebi | last post by:
Hello all, I'm thinking about overwriting the ListItem, so it can contain x additional values (not only one). Has anybody ever tried this? Has someone got an example (C#)? Can DropDownList...
5
by: DC Gringo | last post by:
I have a dropdownlist that, upon form submission, I'd like to maintain the selected value when I get my result...how do I do that? <asp:dropdownlist Font-Size="8" id="ddlCommunities"...
8
by: tshad | last post by:
Can you databind a dropdownlist to another dropdownlist? I have 2 identical list. I am getting my data from a DataReader, so as soon as I have bound the first DDL, I can't do it again to the next...
0
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though...
2
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
2
by: =?Utf-8?B?VmljdG9yaW91czE=?= | last post by:
When the editcommand is execured for my datagrid the dropdown list appears for the bound item status. However, the item selected by default does not match the unedited data. How do I make the...
0
by: andy | last post by:
Hi, I have a form uses several dropdownlists to narrow a set of criteria. ( This is in turn used to control what is shown on a gridview. ) With each, the user selects an entry and then the next...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.