Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert DropDownList to a Label

Posted on 2004-09-16
13
Medium Priority
?
1,097 Views
Last Modified: 2008-02-01
Hi,

I have a DropDownList that I populate with value from a Database.

The number of values that appear in the DropDownList is variable, and can range from 1 vaule to over 50 values.

When the total number of values in the DropDownList is 1, what I want to do is convert the DropDownList into a Label with the text value of the single value returned from the database.

Make sense?

OK, how do I do this???

Thanks in advance.

Steve.
0
Comment
Question by:ive5005s
[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
  • 7
  • 3
  • 2
  • +1
13 Comments
 

Author Comment

by:ive5005s
ID: 12075183
Oh, I'm coding behind in VB.NET.

Cheers.
0
 
LVL 4

Assisted Solution

by:Kaarthick
Kaarthick earned 120 total points
ID: 12075265
There is no such option to convert a ComboBox to Label, but the trick is to use both Label and Combo.

Place both tools in your page. Hide both combo and Label initially. Use datareader to get the values. If the datareader contains more than one value then diplay it in the Combo and leave the Label as such.

If the condition fails i.e., if there is single row then hide the Combo and display the value in the Label instead.
0
 

Author Comment

by:ive5005s
ID: 12075364
Thanks Kaarthick, I like that method.

However, I'm binding the DropDownList to a DataSet.

So, how do I check if the DataSet contains more than one value???
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Expert Comment

by:Kaarthick
ID: 12075519
You should use DataReader and not DataSet because a DataSet extracts whole result adn you cannot perform the mentioned operations. So if you use DataReader then you can loop through values.
Hope you get my point.
0
 
LVL 9

Accepted Solution

by:
Thalox earned 200 total points
ID: 12075608
you could also use dataset.

before binding the dataset to your list, check how many rows it contains

dataset1.Tables(0).Rows.Count > 1

if true, bind the list, else set the value to the label and make it visible

label1.Text = dataset1.Tables(0).Rows(0)("value")

I'm not sure, whether this is corect vb code, but it should be something like this

Thalox
0
 

Author Comment

by:ive5005s
ID: 12075635
OK, how do I check if the datareader contains more than one value?
0
 

Author Comment

by:ive5005s
ID: 12075649
Thank Thalox, I'll try that.
0
 
LVL 4

Expert Comment

by:Kaarthick
ID: 12075652
Good try Thalox, yes you can try that too.
0
 
LVL 33

Expert Comment

by:raterus
ID: 12076365
If you could see yourself using this over and over I'd make your own control that implements this functionality, then you'd just have to use this whenever you wanted this, but if this is a one time thing, forget it :-)
0
 

Author Comment

by:ive5005s
ID: 12076872
This is something I'll be using a few times.

However, I'm not that experienced in creating my own controls.

How do I do this?
0
 
LVL 33

Assisted Solution

by:raterus
raterus earned 80 total points
ID: 12077577
Well this is something other articles will be much better at than I could explain.

http://www.aspalliance.com/cookbook/downloads/pdfs/0672325241_ch03.pdf

Here is what I'd do, this article will help you explain if you read it over..and over.

I'd create a new control that extends the dropdownlist.  then in the render event, if there was only one item, just output that item using the HtmlTextWriter, otherwise render the control as usual.

--Michael
0
 

Author Comment

by:ive5005s
ID: 12082660
Cheers.
0
 

Author Comment

by:ive5005s
ID: 12088671
Thanks for all the help guys.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

670 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