首页>教程>ASP.NET教程>ASP.NET ListItem 控件

需要支持?

如果通过文档没办法解决您的问题,请提交工单获取我们的支持!

ASP.NET ListItem 控件

内容纲要

ASP.NET ListItem 控件可创建列表中的一个项目

此控件与以下列表控件一同使用

<asp:ListBox>

<asp:RadioButtonList>

<asp:BulletedList>

语法

<asp:ListItem 
    Enabled="True|False" 
    Selected="True|False" 
    Text="label" 
    Value="value" 
/>

属性

属性描述.NET
Attributes可选的。此类不直接支持的 ListItem 的属性名和值对的集合1.0
Enabled可选的。规定是否禁用或启用项目2.0
Selected可选的。规定是否选定该项1.0
Text可选的。在 ListItem 中显示的文本1.0
Value可选的。ListItem 的值1.0

Web 控件标准属性

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

如需完整描述,请访问 Web 控件标准属性

控件标准属性

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

如果想要查看完整描述,可以访问我们的 控件标准属性

有可能使用 Text 或 Value 属性以及 inner HTML 文本来设置显示列表项的文本

范例

<asp:ListItem Value="Text1" Text="Text2">Text3</asp:ListItem>

根据 Text 或 Value 属性以及 inner HTML 文本的组合,可显示不同的文本,并可使用不同的值

下表列出了所有可能的组合以及它们的结果

Inner HTMLText 属性Value 属性显示的文本使用的值
已设置已设置已设置Inner HTMLValue 属性
已设置已设置未设置Inner HTMLInner HTML
已设置未设置已设置Inner HTMLValue 属性
已设置未设置未设置Inner HTMLInner HTML
未设置已设置已设置Text 属性Value 属性
未设置已设置未设置Text 属性Text 属性
未设置未设置已设置Value 属性Value 属性
未设置未设置未设置未设置未设置

由于 Text 和 Value 属性都具有空字符串默认值,所以列表控件中可能有空列表项

范例

带有基本 ListItem 的 BulletedList

<!DOCTYPE html>
<meta charset="utf-8" />
<form runat="server">
<asp:BulletedList runat="server">
<asp:ListItem Text="Item1" />
<asp:ListItem Text="Item2" />
</asp:BulletedList>
</form>

范例中,我们展示了 .aspx 文件中带有两个 ListItem 的 BulletedList 控件

带有不同属性的 ListItem 的 ListBox

<!DOCTYPE html>
<meta charset="utf-8" />
<form runat="server">
<asp:ListBox runat="server">
<asp:ListItem Text="Text1" />
<asp:ListItem Value="Text3" Text="Text1">Text2</asp:ListItem>
<asp:ListItem Value="Text3" />
</asp:ListBox>
</form>

范例中,我们带有几个 ListItem 的 ListBox 控件列表中的项目使用了不同的属性来显示 ListItem 的文本

带有被禁用的 ListItem 的 ListBox

<!DOCTYPE html>
<meta charset="utf-8" />
<form runat="server">
<asp:ListBox runat="server">
<asp:ListItem Text="Item1" />
<asp:ListItem Text="Item2" />
<asp:ListItem Text="Item3" />
<asp:ListItem Text="Item4" enabled="False"/>
</asp:ListBox>
</form>

范例中,我们展示了一个带有被禁用的 ListItem 的 ListBox 控件

带有已选的 ListItem 的 RadioButtonList

<!DOCTYPE html>
<meta charset="utf-8"/>

<form runat="server">
<asp:RadioButtonList runat="server">
<asp:ListItem Text="Item1" />
<asp:ListItem Text="Item2" />
<asp:ListItem Text="Item3" />
<asp:ListItem Text="Item4" selected="True"/>
</asp:RadioButtonList>
</form>

范例中,我们展示了一个带有已选 ListItem 的 RadioButtonList 控件

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
今日签到
有新私信 私信列表
搜索