首页 > 开发 > .Net > 正文

通过事例学习.net的WebForms技术(三)

2018-10-16 21:06:57
字体:
来源:转载
供稿:网友
通过事例学习.net的WebForms技术(三)
/*
豆腐制作 都是精品
http://www.asp888.net 豆腐技术站
如转载 请保留完整版权信息
*/
DropDownList:
DropDownList 对应的Form 元素中的 <select ..> 我们同样对他的定义有两种方式
<asp:DropDownList id="dropdownlist1" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
</asp:DropDownList>
代码定义方式:
DropDownList dropdownlist1=new DropDownList();

比较关键的用到了属性主要是:
SelectedItem 这个属性是一个ListItem Class 我们紧接着就来讲解这个ListItem 属性

ListItem 属性,

由于我们对于DropDownList 最为关心的就是我们在对DropDownList进行选择以后我们得到的结果
所以,我们对ListItem 的最为关心的属性自然就是Text和 Value 这两个属性
Text 是ListItem 在外表所显示出来的结果
Value 是我们所选择的 Item 的真正的数值

综上,我们总结一下DropDownList 的 SelectedItem 属性的使用方法
dropdownlist1.SelectedItem.Text 和 dropdownlist1.SelectedItem.Value


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选