在Repeater 中绑定 DropDownList


理论上下面这段代码可行的,结果却怎么也显示不出来,找了半天,发现这段代码的事件放错了应该放在:Repeater1_ItemDataBound事件中,而我放到了Repeater1_ItemCommand事件中,所以悲剧了。。。

记录下来,以免下次还犯同样的错误。
注意事件!


protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DropDownList ddl = (DropDownList)e.Item.FindControl("DropDownList2") as DropDownList;
        ddl.DataSource = new BLL.AdminManger().SelectAll();//这里是你要绑定的数据源;
        ddl.DataTextField = "userName";
        ddl.DataValueField = "id";
        ddl.DataBind();
}

你可能感兴趣的:(绑定 DropDownList)