zoukankan      html  css  js  c++  java
  • 服务器控件的几个属性 SelectedIndex、SelectedItem、SelectedValue、SelectedItem.Text、selectedItem.value

    转自http://blog.csdn.net/iqv520/article/details/4419186

    1. SelectedIndex ——选项的索引,为int,从0开始,可读可写

    2. SelectedItem ——选择项,是一个对象,为ListItem,只读不写

    3. SelectedValue —— 选项的值,为string, 只读不写

    4. SelectedItem.Text ——选项的文本内容,与 SelectedItem的值一样为 string,可读可写

    5. SelectedItem.Value ——选项的值,与 SelectedValue的值一样为 string,可读可写

    示例

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="dropdown.aspx.cs" Inherits="dropdown" %>
    
    <!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>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem Value="1">北京</asp:ListItem>
                <asp:ListItem Value="2">上海</asp:ListItem>
                <asp:ListItem Value="3">广州</asp:ListItem>
            </asp:DropDownList>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="check" /><br />
            <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
            <br />
            <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
            <br />
            <asp:Label ID="Label3" runat="server" Text=""></asp:Label><br />
            <asp:Label ID="Label4" runat="server" Text=""></asp:Label>
            <br />
            <asp:Label ID="Label5" runat="server" Text=""></asp:Label>
        
        </div>
        </form>
    </body>
    </html>
    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 dropdown : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = "selectedIndex=" + DropDownList1.SelectedIndex;
            Label2.Text = "selectedItem=" + DropDownList1.SelectedItem;
            Label3.Text = "selectedValue=" + DropDownList1.SelectedValue;
            Label4.Text = "selectedItem.text=" + DropDownList1.SelectedItem.Text;
            Label5.Text = "selectedItem.value=" + DropDownList1.SelectedItem.Value;
        }
    }

  • 相关阅读:
    Android消息机制(Handler)详述
    Android自定义组件-以饼状图并实现点击事件为例
    Markdown中tab的解析与4个空格 问题
    策略模式(Strategy)
    观察者模式(Observer)
    适配器模式(Adapter Class/Object)
    建造者模式(Builder)
    简单工厂模式、工厂方法模式、抽象工厂模式
    单例模式(Singleton)
    工具推荐:前后端一体化部署,效能提升开源“神器”
  • 原文地址:https://www.cnblogs.com/Tanghongchang/p/10695229.html
Copyright © 2011-2022 走看看