当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > Web服务器控件:ListBox控件

ASP.NET
动态加载Js代码到Head标签中的脚本
asp.net Parameters.AddWithValue方法在SQL语句的 Where 字句中的用法
ASP.NET 运行时错误: 没有为扩展名“.asax”注册的生成提供程序修正版
Convert.ToInt32与Int32.Parse区别及Int32.TryParse
WebService出现"因 URL 意外地以 结束,请求格式无法识别"的解决方法
asp.net(C#) Xml操作(增删改查)练习
asp.net 分页sql语句(结合aspnetpager)
asp.net开发与web标准的冲突问题的一些常见解决方法
asp.net Repeater中使用if的代码
Asp.net FCKEditor 2.6.3 上传文件没有权限解决方法
C# 命名规则(挺不错的)
asp.net 动态生成控件并获取其值
使用DataGrid中扩展ItemRenderer和HeaderRenderer进行操作
asp.net Hashtable 遍历写法
asp.net GridView和DataList实现鼠标移到行行变色
C# 邮件地址是否合法的验证
.net发送邮件实现代码
ASP.Net 上传图片并生成高清晰缩略图
asp.net 事件与委托分析
C# 无限级分类的实现

ASP.NET 中的 Web服务器控件:ListBox控件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 106 ::
收藏到网摘: n/a

阅读此文请先查看:ASP.NET入门教程:Web服务器控件,简单讲述了Web服务器控件的使用方法。

定义和用法

ListBox 控件用于创建但选货多选的下拉列表。

ListBox 控件中的可选项目是通过 ListItem 元素定义的!

ListBox Web控件和DropDownList Web控件的功能几乎是一样,只是 ListBox Web 控件是一次将所有的选项都显示出来。SelectionMode属性可以设置是单选还是多选,默认是Single。

提示:该控件支持数据绑定!

属性

属性 描述 .NET
Rows 在列表中显示的行数。 1.0
SelectionMode 允许单选还是多选。 1.0

Web 控件标准属性

AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth,
CssClass, Enabled, Font, EnableTheming, ForeColor, Height, IsEnabled,
SkinID, Style, TabIndex, ToolTip, Width

控件标准属性

AppRelativeTemplateSourceDirectory, BindingContainer, ClientID, Controls,
EnableTheming, EnableViewState, ID, NamingContainer, Page, Parent, Site,
TemplateControl, TemplateSourceDirectory, UniqueID, Visible

语法

<ASP:ListBox
  Id="控件名称"
  Runat="Server"
  AutoPostBack="True | False"
  DataSource="<%数据源%>"
  DataTextField="数据源的字段"
  DataValueField="数据源的字段"
  Rows="一次要显示的列数"
  SelectionMode="Single | Multiple"
  OnSelectedIndexChanged="事件程序名称"
>
  <ASP:ListItem/>
</ASP:ListBox>

实例

<% Page Language=C#>
<Html>
<Form Id="Form1" Runat="Server">
请选择您喜欢的明星(单选):<br>
  <ASP:ListBox Id="ListBox1" Runat="Server">
 <ASP:ListItem>张学友</ASP:ListItem>
    <ASP:ListItem>刘德华</ASP:ListItem>
    <ASP:ListItem>黎明</ASP:ListItem>
    <ASP:ListItem>大傻</ASP:ListItem>
     <ASP:ListItem>郭富城</ASP:ListItem>   
  </ASP:ListBox>
</Form>
</Html>