在我的应用程序中,我有一个下拉列表和一个标签.... [英] in my application i have one dropdownlist and one label....

查看:61
本文介绍了在我的应用程序中,我有一个下拉列表和一个标签....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨到每一个......

在我的应用程序中我有一个下拉列表和一个标签,给了一些值到下拉列表我的qustn是如果我选择一个列表项它将显示自动标签所以如何编写这个代码

提前提交

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

推荐答案

在下拉列表中选择索引转换请求



将标签文本设置为selecteditem



In the dropdownlist selectedindexchangedevent

set the label text to selecteditem

Label1.Text=dropdownlist1.SelectedText.ToString()





更新:



为下拉列表添加AutoPostBack属性为true



Update:

Add AutoPostBack property to true for dropdown


下面是.aspx文件的代码



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>





现在将下面的.cs文件放入DropDownList1_SelectedIndexChanged活动中





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 :)
cheers...


这篇关于在我的应用程序中,我有一个下拉列表和一个标签....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆