Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET GimmeCode Homework , +
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 28-Jan-13 23:34pm
Edited 30-Jan-13 3:44am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In the dropdownlist selectedindexchangedevent
 
set the label text to selecteditem
 
Label1.Text=dropdownlist1.SelectedText.ToString()
 
Update:
 
Add AutoPostBack property to true for dropdown
  Permalink  
v2
Comments
mahesh202 at 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 at 29-Jan-13 6:14am
   
add autopostback=true for dropdown
Rate this: bad
good
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" "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
 
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 Smile | :)
cheers...
  Permalink  
Comments
Marcus Kramer at 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)



Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
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