asp:DropDownList用法
生活随笔
收集整理的這篇文章主要介紹了
asp:DropDownList用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
DropDownList前臺:
<asp:DropDownList runat="server" ID="drop" AutoPostBack="true" OnSelectedIndexChanged="drop_SelectedIndexChanged"></asp:DropDownList>DropDownList后臺:
protected void Page_Load(object sender, EventArgs e){//EF引入數據,或者自定義的list<對象>集合using (testEntities db =new testEntities()) {this.drop.DataSource = db.users.ToList();//顯示的this.drop.DataTextField = "userName";//實際值this.drop.DataValueField = "id";this.drop.DataBind();}}獲取值的后臺方法:
protected void drop_SelectedIndexChanged(object sender, EventArgs e){string selectedValue = this.drop.SelectedValue;int selectedIndex = this.drop.SelectedIndex;ListItem selectedItem = this.drop.SelectedItem;}效果如下:
?
很直白,希望能幫助到你。
總結
以上是生活随笔為你收集整理的asp:DropDownList用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 程序员养发(老师付推荐)
- 下一篇: 时间和空间复杂度概述【Java _dem