ASP.NET DropDownList控件的使用方法

ASP.NET DropDownList控件的使用方法,学习asp.net的朋友没用过这个控件的朋友可以参考下。

1. 数据绑定

复制代码 代码如下:

this.DropDownList1.DataSource = CategoryManager.getCategories();
DropDownList1.DataValueField = "id";//用来设置下拉列表选中的 Value 值
DropDownList1.DataTextField = "name";//为下拉列表选项显示的值
DropDownList1.DataBind();


2.读取数据
复制代码 代码如下:

int categoryId = int.Parse(this.DropDownList1.SelectedItem.Value);//获取下拉列表中选中的值

以上就是ASP.NET DropDownList控件的使用方法的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » ASP编程