我们有10个下拉列表,数据应该从SQL Server绑定到使用foreach循环的下拉列表
答案 0 :(得分:0)
private void bindDropdowns(DataSet ds)
{
foreach (Control control in form1.Controls)
{
if ((control.GetType() == typeof(DropDownList)))
{
((DropDownList)(control)).DataTextField = "InformationReview";
((DropDownList)(control)).DataValueField="InformationReviewID";
((DropDownList)(control)).DataSource = ds.Tables[0];
((DropDownList)(control)).DataBind();
((DropDownList)(control)).Items.Insert(0, new ListItem("-Select--", "0"));
}
}}