Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Access more than 2 fields with Dropdown list

Reply
Thread Tools

Access more than 2 fields with Dropdown list

 
 
Elsa Luiz
Guest
Posts: n/a
 
      11-14-2003
Hi,
I would like to access the value of a third field of the query that I
used to populate my dropdown list. Is there a way to do that? For
example, in the following example I would like to access valueC.

SqlCommand sqlCmdLoad1 = new SqlCommand("SELECT valueA, valueB, valueC
FROM myTable", sqlConnection1);
sqlConnection1.Open();
SqlDataReader dr1 = sqlCmdLoad1.ExecuteReader();
ddl.DataSource = dr1;
ddl.DataTextField = "valueA";
ddl.DataValueField = "valueB";
ddl.DataBind();
dr1.Close();
sqlConnection1.Close();

I know that to access valueA I would use: ddl.SelectedItem.Text for
example, to access valueB I would use: ddl.SelectedValue, and to
access valueC, is there any way?

Thanks,
Elsa
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      11-14-2003
Hi,

on such cases you could create the value field to be one concatenated field
(that's done in SQL, separator could be say a comma) which is then assigned
to DataValueField property of DDL. When you access the value, you could get
what you need by splitting the value with comma.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Elsa Luiz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ...
> Hi,
> I would like to access the value of a third field of the query that I
> used to populate my dropdown list. Is there a way to do that? For
> example, in the following example I would like to access valueC.
>
> SqlCommand sqlCmdLoad1 = new SqlCommand("SELECT valueA, valueB, valueC
> FROM myTable", sqlConnection1);
> sqlConnection1.Open();
> SqlDataReader dr1 = sqlCmdLoad1.ExecuteReader();
> ddl.DataSource = dr1;
> ddl.DataTextField = "valueA";
> ddl.DataValueField = "valueB";
> ddl.DataBind();
> dr1.Close();
> sqlConnection1.Close();
>
> I know that to access valueA I would use: ddl.SelectedItem.Text for
> example, to access valueB I would use: ddl.SelectedValue, and to
> access valueC, is there any way?
>
> Thanks,
> Elsa



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Like all great travelers, I have seen more than I remember andremember more than I have seen. shenrilaa@gmail.com Java 0 03-06-2008 08:11 AM
Like all great travelers, I have seen more than I remember andremember more than I have seen. shenrilaa@gmail.com C++ 0 03-05-2008 08:41 AM
Like all great travelers, I have seen more than I remember andremember more than I have seen. shenrilaa@gmail.com C Programming 0 03-05-2008 03:26 AM
Q: multiple fields in dropdown list =?Utf-8?B?SklNLkgu?= ASP .Net 3 04-12-2005 07:45 PM
Q: How to use DataGrid in Edit Mode -- with more fields than shown? Sky ASP .Net 2 01-29-2004 11:02 AM



Advertisments