Click here to Skip to main content
16,004,761 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<asp:DropDownList ID="DropDownList1" runat="server" 
                onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                <asp:ListItem>1
                <asp:ListItem>2
                <asp:ListItem>3
                <asp:ListItem>4
                <asp:ListItem>5
                <asp:ListItem>6

this is a dropdown
ASP.NET
<asp:Label ID="Label2" runat="server" Text="Label">

and this is a label

now i want to update a label on select of dropdown or change in dropdown and the updation shou ld be performed by ajax and i hv my own code on this event:
C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
       int factor = DropDownList1.SelectedIndex + 1;
       int pricein = int.Parse(Label2.Text);
       int totalPrice = pricein * factor;
       Label2.Text = totalPrice.ToString();
   }
Posted
Updated 9-Sep-13 21:20pm
v3
Comments
phil.o 10-Sep-13 3:22am    
Please have a look at your previous question ; I updated my solution because I saw an potential problem.
Salman622 10-Sep-13 3:27am    
you have given the label text as Label


what you want to do

weather u want to display as eg:- Label3.... 3 is your dropdown selected text and Label is Label2 text

Set AutoPostBack="true" for DropDownList.
 
Share this answer
 
ASP.NET
<asp:label id="Label2" runat="server" xmlns:asp="#unknown">Text="Label"></asp:label>

Here Text of Label is "Label" and in the following line you are parsing it to integer.
C#
int pricein = int.Parse(Label2.Text);


What will be the output? :)

Also as thatraja suggested, you should set AutoPostBack="true" for DropDownList in order to fire DropDownList1_SelectedIndexChanged Event.
 
Share this answer
 
Comments
Omprakash Kukana 10-Sep-13 4:14am    
ya its working but i want to update label from ajax
Follow the answers here - Ajax on dropdownlist selected index changed event.

You need to use Ajax UpdatePanel.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900