repeater之嵌套绑定,使用初学者。。
废话不多说了,我就直接上代码了。。

以下是cs代码:
1 //下拉绑定 2 void autoOldbind() 3 { 4 this.DropDownList1.DataSource = OldBLL.QueryAll(); 5 this.DropDownList1.DataTextField = "OldName"; 6 this.DropDownList1.DataValueField = "ID"; 7 this.DropDownList1.DataBind(); 8 } 9 //大类绑定 10 void autobind() 11 { 12 this.auto_repOld.DataSource = OldBLL.QueryAll(); 13 this.auto_repOld.DataBind(); 14 } 15 16 //嵌套绑定 17 protected void repeat_dataBind(object sender, RepeaterItemEventArgs e) 18 { 19 Repeater rep = e.Item.FindControl("auto_repyong") as Repeater;//找到里层的repeater对象 20 //DataRowView row = (DataRowView)e.Item.DataItem; 21 _Old dv = (_Old)e.Item.DataItem; 22 //提取大类ID 23 int CategorieId = Convert.ToInt32(dv.ID); 24 _Young y = new _Young(); 25 y.OldID = CategorieId; 26 rep.DataSource = YoungBLL.QueryYoung(y); 27 rep.DataBind(); 28 } 29 30 //增增小类 31 protected void Button1_Click(object sender, EventArgs e) 32 { 33 _Young y = new _Young(); 34 string youngtest = this.TextBox1.Text.Trim(); 35 int OLdIndex =Convert.ToInt32(this.DropDownList1.SelectedItem.Value); 36 y.OldID = OLdIndex; 37 y.YoungName = youngtest; 38 YoungBLL.AddYoung(y); 39 autobind(); 40 this.auto_repOld.ItemDataBound += new RepeaterItemEventHandler(repeat_dataBind); 41 }
以下是操作界面:

欢迎大家来拍砖。。

浙公网安备 33010602011771号