您的位置首页生活小窍门

Repeater嵌套时,如何给内层嵌套的Repeater中的一个按钮赋值?

Repeater嵌套时,如何给内层嵌套的Repeater中的一个按钮赋值?

直冲芹羡接btn肯定是错的,想一下内层的repeater可能有多项,每项都可能有Button而且既散拍然要赋值,肯定是在绑定之后,否则值就被首滑覆盖了 protected void rptHotel_ItemDataBound(object sender, RepeaterItemEventArgs e) { HotelDataOperate hdo = new HotelDataOperate(); if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rpt = e.Item.FindControl("rptRoom") as Repeater; DataRowView rowv = (DataRowView)e.Item.DataItem; int typeid = Convert.ToInt32(rowv["id"]); //Button btn = e.Item.FindControl("rptRoom").FindControl("btnBook") as Button; //btn.Text = "XXXX"; //这里会有一个if语句给Text属性赋不同值。 rpt.DataSource = hdo.getRoomList(typeid); rpt.DataBind(); Button btn = null; foreach (RepeaterItem item in rpt.Items) { btn = item.FindControl("btnBook") as Button; if (btn != null) { btn.Text = "xxxx"; } } } }