| | |
Get Dropdown list value - set label text
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
Hi everyone,
I would like to set a label's text when a dropdownlist item is selected
I want the label to display the value of the item, not the text.
Is there any way i can do so without refreshing the page i found the update panel loads far too long for my liking.
Javascript ???
i would like to do this using attributes
This does not work, can anyone give me some pointers please ??
Thanks in advance
I would like to set a label's text when a dropdownlist item is selected
I want the label to display the value of the item, not the text.
Is there any way i can do so without refreshing the page i found the update panel loads far too long for my liking.
Javascript ???
i would like to do this using attributes
C# Syntax (Toggle Plain Text)
ddBenefitPeriod.Attributes.Add("selectedIndexChanged", string.Format("{0}.innertext = {1}.options[{1}.selectedIndex].value; ", lblBenefitPeriodFactor.ClientID, ddBenefitPeriod.ClientID));
This does not work, can anyone give me some pointers please ??
Thanks in advance
Delphi & C# programmer deluxe...
Try this:
ASP.NET Syntax (Toggle Plain Text)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="daniweb.web.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:dropdownlist ID="Dropdownlist1" runat="server"> <asp:ListItem Value="Value1">Text1</asp:ListItem> <asp:ListItem Value="Value2">Text2</asp:ListItem> </asp:dropdownlist> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </div> </form> </body> </html>
c# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace daniweb.web { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string script = string.Format("javascript:document.getElementById('{0}').innerText = {1}.options[{1}.selectedIndex].value;", Label1.ClientID, Dropdownlist1.ClientID); Dropdownlist1.Attributes.Add("onChange", script); } } }
![]() |
Similar Threads
- Cascading Dropdown list with (AJAX, PHP) (PHP)
- Conditional dropdown List (C#)
- I have tried to set a label to change its text at each time. (Java)
- sending data of a dropdown list from one html page to another without data base (JavaScript / DHTML / AJAX)
- get BLOB from database based on dropdown list selected value (ASP.NET)
- Adding To a list box from multiple text boxes (Visual Basic 4 / 5 / 6)
- from list view to label (Visual Basic 4 / 5 / 6)
- How to make selected index zero for dropdown list box in java script..? (JavaScript / DHTML / AJAX)
- DropDown List (VB.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: how can i get the system admin user id and password into my asp using vb.net
- Next Thread: Delete the file from server
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox click commonfunctions control css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql multistepregistration news novell numerical objects opera panelmasterpagebuttoncontrols radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers






