Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to every one ...
in my application i have one dropdownlist and one label , am given some values to the dropdownlist my qustn is if i select the one list item it will show the label autometically so how to write the code for this one
thanx in advance
Posted
Updated 30-Jan-13 3:44am
v2

In the dropdownlist selectedindexchangedevent

set the label text to selecteditem

C#
Label1.Text=dropdownlist1.SelectedText.ToString()


Update:

Add AutoPostBack property to true for dropdown
 
Share this answer
 
v2
Comments
mahesh202 29-Jan-13 6:04am    
am already taken and try but it is not working exactly
below is my application

drug name : (dropwonlist)
drug compny: label
it will come autometically not after button click event
Santhosh Kumar Jayaraman 29-Jan-13 6:14am    
add autopostback=true for dropdown
Below is code for .aspx file

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:DropDownList runat="server" ID="DropDownList1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true" >
    <asp:ListItem>--SELECT--</asp:ListItem>
    <asp:ListItem>Ford</asp:ListItem>
    <asp:ListItem>Maruti</asp:ListItem>
    <asp:ListItem>BMW</asp:ListItem>
    </asp:DropDownList>

    <asp:Label ID="Label1" runat="server" Visible="false"></asp:Label>
    </div>
    </form>
</body>
</html>


Now put following in .cs file in "DropDownList1_SelectedIndexChanged" Event

C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex > 0)
        {
            Label1.Text = DropDownList1.SelectedItem.Text;
            Label1.Visible = true;
        }
        else
            Label1.Visible = false;
    }
}



Hope it will help u... if it helped then dnt forget to vote :)
cheers...
 
Share this answer
 
Comments
fjdiewornncalwe 30-Jan-13 9:44am    
A couple of notes for you:
1) Don't beg for votes. That is just plain annoying.
2) Please don't provide full code for blatant homework questions. Give them help and guide them along their way, but don't do the work for them.

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