DropDownList1.DataSource = ds; //绑定数据源
DropDownList1.DataTextField = "TypeName"; //文本内容字段
DropDownList1.DataValueField = "TypeId"; //值字段
DropDownList1.DataBind();
ds.Dispose();
取默认值
DropDownList1.SelectedValue = year.ToString();
本文详细介绍了如何在ASP.NET网页中使用DropdownList组件进行数据绑定和初始化,包括设置数据源、文本字段和值字段,以及如何获取默认值。
DropDownList1.DataSource = ds; //绑定数据源
DropDownList1.DataTextField = "TypeName"; //文本内容字段
DropDownList1.DataValueField = "TypeId"; //值字段
DropDownList1.DataBind();
ds.Dispose();
取默认值
DropDownList1.SelectedValue = year.ToString();
648
7742

被折叠的 条评论
为什么被折叠?