473,756 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Web App: Creating labels from drop down list selection

55 New Member
Hi all,

I would like to know a way to add a label to an update panel by using a drop down list selected item.

For example:

There is a list of items in a drop down list, the user selects one then presses the add button next to it and it creates a label in a table next to it.

Here is the code I have at the moment:

Expand|Select|Wrap|Line Numbers
  1. protected void btAdd_Click(object sender, EventArgs e)
  2.     {
  3.         Label lblSelected = new Label();
  4.         lblSelected.Text = ddlAdd.SelectedItem.Text;
  5.         ddlAddingSales.Items.Remove(ddlAdd.SelectedItem);
  6.         UpdatePanel.ContentTemplateContainer.Controls.Add(lblSelected);
  7.     } 
  8.  
Of course with this way though it just keeps writing over the previously created label :(

Many thanks in advance.
Sep 23 '08 #1
5 1943
Frinavale
9,735 Recognized Expert Moderator Expert
Why don't you just append to the existing label instead of creating a whole bunch of controls that are not needed? This would reduce page bloat.

-Frinny
Sep 23 '08 #2
dmj07
55 New Member
I don't understand what you mean, if you mean append to a label already on the webform then I dont have one because I want to dynamically creat them without full page postback. If you could provide me any sample code to show me what you mean that would be helpful.

Many thanks
Sep 23 '08 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Check out the article on how to use dynamic controls in ASP.NET. It should help you understand how to do want you want.

-Frinny
Sep 24 '08 #4
dmj07
55 New Member
Thankyou very much for your help. Although the page was very helpful I need to load the created labels into a update panel inside a modal popup box. I will keep trying though.

Many thanks again.
Sep 24 '08 #5
Frinavale
9,735 Recognized Expert Moderator Expert
Thankyou very much for your help. Although the page was very helpful I need to load the created labels into a update panel inside a modal popup box. I will keep trying though.

Many thanks again.
A Modal pop up box? As in a JavaScript Alert Box?
Labels are .NET controls......a lert boxes are JavaScript and only display text.

You could keep track of the items selected and add them to a String ... you can then add to a JavaScript call that makes an alert box with the string containing the selected items.

-Frinny
Sep 24 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
6314
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
1
2913
by: Dan | last post by:
This is one that has me stumped and I need an expert's input. Any ideas why the values from the second script-generated drop down list isn't recognized by the script to add time values to the text boxes? What this script is suppose to do is change the value of a second drop down list based on the selection from the first. Then a value is chosen from the script generated drop down list in the
5
6526
by: SirPoonga | last post by:
I think I'd have to do a combination of ASP and javascript to do this. What I want to do fill the first drop down box with values from a database query. Then based off that selection fill in the values of another drop down. Let's use the car industry as an example. Lets say I am storing in a database the data and relationships between car make, car type, and car model. So the first drop down box would like all makes. Upon selecting...
2
9472
by: kmnotes04 | last post by:
Is it possible to link one drop-down box to another? For example, if a name is chosen from a drop-down list, can another drop-down list then automatically display the person's office as a result of the choice made in the first drop-down list? If so, how can that be done? I am working with 'Teach Yourself Microsoft Access' and I didn't see it discussed in that book (if it's even possible to do). Or would I just have to create linked tables...
2
12622
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will select any skill in 1st drop down list then i'll select % of this skill in the 2nd list box , based on the percentage i've selected in the 2nd list box it has to display 2 sets of drop down list boxes at run time one for selecting skill and
3
2996
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in the drop down box to go back to what the value was before the user tried to change it, but at that point I will not know what the original value was. Or is there a drop down control "revert" method, or is there any way of knowing what the original...
5
3165
by: E.T. Grey | last post by:
I have a form that is populated with a drop down list and a list box. I want to be able to automatically populate the list box, whenever a user selects a new item from the drop down list. Is there a way of doing this as soon as a new item is selected from the drop down box? (I'm trying to mimic a rich client interface in a web browser).
0
2103
by: TD | last post by:
I have a combobox that is sometimes slow to drop down when clicked on. If you select an item in the list that is near the top of the list then the next time you click on the combobox it drops down fast for you to make another selection. If you click on an item from the list that is way down the list then the next time you click on the combobox it takes several seconds for it to drop down so you can make another selection The combobox is...
9
3628
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have to create the dynamic controls in the OnInit stage of the lifecycle. Since data from static controls is not yet available in the OnInit stage I can't know what dynamic control I have to create.
0
9431
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9255
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9844
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9819
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8688
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7226
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6514
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5119
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3326
muto222
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.