[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Populating Drop-Down Control

Posted on 2003-11-15
2
Medium Priority
?
966 Views
Last Modified: 2010-05-18
I have a table with two columns which I would like to drive a drop-down control. I would like the DataTextField to be the values of the two columns concatenated together with some punctuation added, and the DataValueField to be the value of the second column only.

Example:

Data: Column 1: "Attendee"
         Column 2: "150"

In the Drop-Down: DataTextField: "Attendee ($150)"
                            DateValueField: "150"

I can't seem to concatenate the columns together, either in the SQL statement itself, or by going through the data in a datareader and formatting the entries into the drop-down.

I have seen some VB samples like this:

   Loop through a datareader and for each row:

   droplist.Items.Add(New ListItem("textfield", "valuefield"))

but I can't get anything like this to work in C#.

Thanks for the help.
Ted
0
Comment
Question by:tk3
[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 Comments
 
LVL 10

Accepted Solution

by:
smegghead earned 750 total points
ID: 9756953
In the SQL statement, can't you just have

select fdesc+' ($'+fval+')' as col1,fval as col2 from ...

then just use col1 and col2 as your fields ?

HTH

Smg.
0
 

Expert Comment

by:onura
ID: 9771113

Hi there,
Do you mean something like this?

// assuming that you have a list named myList containing elements type of myListItem
// and you have a drop down list named myDropDownList
foreach (myListItem li in myList)
{
  myDropDownList.Items.Add(new ListItem(li.Text,li.Value));

}

You may populate the collection to be iterated from your database query and use the dataset, or if you are using a database access layer, you may use your own types of collections.


However there is another way to populate these dropdownlists, you may directly set the datasource of the dropdownlist to a 2 column dataset that you populated.

Hope this helps,
Sincerely,

Onur

www.onura.net



0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

649 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