Click here to Skip to main content
12,759,761 members (33,330 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
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 29-Jan-13 0:34am
Updated 30-Jan-13 4:44am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In the dropdownlist selectedindexchangedevent

set the label text to selecteditem



Add AutoPostBack property to true for dropdown
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 J 29-Jan-13 6:14am
add autopostback=true for dropdown
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Below is code for .aspx file

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
    <asp:DropDownList runat="server" ID="DropDownList1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true" >

    <asp:Label ID="Label1" runat="server" Visible="false"></asp:Label>

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

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;
            Label1.Visible = false;

Hope it will help u... if it helped then dnt forget to vote :)
Marcus Kramer 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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100