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

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,可读可写

光看文字可能不太理解,我也是通过程序来加深理解的,下面举个例子:

前台代码:

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="dropdown.aspx.cs" Inherits="dropdown" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" >
  4. <head runat="server">
  5. <title>无标题页</title>
  6. </head>
  7. <body>
  8. <form id="form1" runat="server">
  9. <div>
  10. <asp:DropDownList ID="DropDownList1" runat="server">
  11. <asp:ListItem Value="1">北京</asp:ListItem>
  12. <asp:ListItem Value="2">上海</asp:ListItem>
  13. <asp:ListItem Value="3">广州</asp:ListItem>
  14. </asp:DropDownList>
  15. <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="check" /><br />
  16. <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
  17. <br />
  18. <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
  19. <br />
  20. <asp:Label ID="Label3" runat="server" Text=""></asp:Label><br />
  21. <asp:Label ID="Label4" runat="server" Text=""></asp:Label>
  22. <br />
  23. <asp:Label ID="Label5" runat="server" Text=""></asp:Label>
  24. </div>
  25. </form>
  26. </body>
  27. </html>

后台代码:

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. public partial class dropdown : System.Web.UI.Page
  12. {
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15. }
  16. protected void Button1_Click(object sender, EventArgs e)
  17. {
  18. Label1.Text = "selectedIndex=" + DropDownList1.SelectedIndex;
  19. Label2.Text = "selectedItem=" + DropDownList1.SelectedItem;
  20. Label3.Text = "selectedValue=" + DropDownList1.SelectedValue;
  21. Label4.Text = "selectedItem.text=" + DropDownList1.SelectedItem.Text;
  22. Label5.Text = "selectedItem.value=" + DropDownList1.SelectedItem.Value;
  23. }
  24. }

运行效果如下:

    

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

dropdownlist控件的几个属性selectedIndex、selectedItem、selectedValue、selectedItem.Text、selectedItem.value的区别的更多相关文章

  1. DropDownList 控件

    今天打算学习下dropdownlist控件的取值,当你通过数据库控件或dataset绑定值后,但又希望显示指定的值,这可不是简单的值绑定就OK,上网搜了一些资料,想彻底了解哈,后面发现其中有这么大的奥 ...

  2. DropDownList控件

    1.DropDownList控件 <asp:DropDownList runat="server" ID="DropDownList1" AutoPost ...

  3. DropDownList 控件不能触发SelectedIndexChanged 事件

    相信DropDownList 控件不能触发SelectedIndexChanged 事件已经不是什么新鲜事情了,原因也无外乎以下几种: 1.DropDownList 控件的属性 AutoPostBac ...

  4. 三级联动---DropDownList控件

    AutoPostBack属性:意思是自动回传,也就是说此控件值更改后是否和服务器进行交互比如Dropdownlist控件,若设置为True,则你更换下拉列表值时会刷新页面(如果是网页的话),设置为fl ...

  5. 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件增加了 PlaceholderText 属性

    [源码下载] 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件 ...

  6. c#中DropDownList控件绑定枚举数据

    c# asp.net 中DropDownList控件绑定枚举数据 1.枚举(enum)代码: private enum heros { 德玛 = , 皇子 = , 大头 = , 剑圣 = , } 如果 ...

  7. DropDownList控件学习

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  8. 使用shape来定义控件的一些显示属性

    Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体的了解,稍作总结 先看下面的代码: <shape> <!-- 实心 -- ...

  9. WPF布局控件与子控件的HorizontalAlignment/VerticalAlignment属性之间的关系

    WPF布局控件与子控件的HorizontalAlignment/VerticalAlignment属性之间的关系: 1.Canvas/WrapPanel控件: 其子控件的HorizontalAlign ...

随机推荐

  1. Flink Program Guide (4) -- 时间戳和Watermark生成(DataStream API编程指导 -- For Java)

    时间戳和Watermark生成 本文翻译自Generating Timestamp / Watermarks --------------------------------------------- ...

  2. php 表单校验函数库(判断email格式是否正确、http地址是否合法有效、手机号码是否合法)

    /** * 表单校验函数库 */ /** * 判断email格式是否正确 * @param $email */ function is_email($email) { return strlen($e ...

  3. python排序(冒泡, 快速)

    之前用java时学习的一些基础算法,今天在python上也研究下. 1. 冒泡排序 算法步骤: 50   30   70  90 10 1)50 跟 30 比不用交换. 2)步数+1, 30 跟70比 ...

  4. MSSQL 日期操作函数 总结

    set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER FUNCTION [dbo].[ufn_getDateOfWeek] (@Date Dateti ...

  5. 使用instantclient_11_2 和PL/SQL Developer工具包连接oracle 11g远程数据库

    本文转自CSDN博客,http://blog.csdn.net/helifengwell/archive/2010/08/18/5820434.aspx 1,先到Oracle站点下载Instant C ...

  6. CodeForces 111B - Petya and Divisors 统计..想法题

    找每个数的约数(暴力就够了...1~x^0.5)....看这约数的倍数最后是哪个数...若距离大于了y..统计++...然后将这个约数的最后倍数赋值为当前位置...好叼的想法题.... Program ...

  7. Memcached基本架构和思想

    Memcached采用客户端-服务器的架构,客户端和服务器端的通讯使用自定义的协议标准,只要满足协议格式要求,客户端Library可以用任何语言实现. 从用户的角度来说,服务器维护了一个键-值关系的数 ...

  8. JAVA策略模式

    <JAVA与模式>之策略模式 在阎宏博士的<JAVA与模式>一书中开头是这样描述策略(Strategy)模式的: 策略模式属于对象的行为模式.其用意是针对一组算法,将每一个算法 ...

  9. UCML快速开发平台学习1-UCML环境安装

           最近公司项目时间紧张,经过各位大神的PK,决定用多年前话10W采购过来,一直被雪藏的UCML来开发.为啥花了钱买回来不用我就不吐槽了. UCML安装         翻看安装手册,貌似不 ...

  10. 2014.12.01 B/S 使用VS建立Web网站

    要求:从hr数据库info表读取数据,在Web网站中显示为如图: 用DW绘制一个表格,然后将代码拷贝到新建的网站主页代码中 <div> <table bgcolor=" w ...