zoukankan      html  css  js  c++  java
  • dropdownlist控件的几个属性selectedIndex、selectedItem、selectedValue、selectedItem.Text、selectedItem.value的区别

    1. selectedIndex——指的是dropdownlist中选项的索引,为int,从0开始,可读可写

    2. selectedItem——指的是选中的dropdownlist中选项,为ListItem,只读不写

    3. selectedValue——指的是选中的dropdownlist中选项的值,为string, 只读不写

    4. selectedItem.Text——指的是选中的dropdownlist中选项的文本内容,与selectedItems的值一样为string,可读可写

    5. selectedItem.value——指的是选中的dropdownlist中选项的值,与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;  
        }  
    }  
    

      

    原文

  • 相关阅读:
    年度榜单:2013年最流行的15款免费英文字体
    优秀案例:12个精美的设计工作室 & 设计公司网站
    jQuery Label Better – 友好的表单输入框提示插件
    CSS 魔法系列:纯 CSS 绘制各种图形《系列六》
    Feathers JS – 基于 Express 构建数据驱动的服务
    Node.app – 用于 iOS App 开发的 Node.js 解释器
    100款免费的圣诞节矢量图标素材(PSD & SVG)
    Web 开发人员不能错过的 jQuery 教程和案例
    Headroom.js – 快速响应用户的页面滚动操作
    10个实用的 CSS3 按钮效果制作教程
  • 原文地址:https://www.cnblogs.com/ZkbFighting/p/9469267.html
Copyright © 2011-2022 走看看