| | |
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 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox class click commonfunctions compatible confirmationcodegeneration content contenttype countryselector courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu edit expose flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery list listbox login menu microsoft mono mouse mssql multistepregistration nameisnotdeclared news numerical objects order panelmasterpagebuttoncontrols problem radio ratings rotatepage save schoolproject search security serializesmo.table silverlight smartcard sql sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopemnt webservice wizard xml youareanotmemberofthedebuggerusers






