Page code
<formID= "Form1"runat= "Server"> <Asp:repeaterID= "Rptcategories"runat= "Server"OnItemCommand= "Rptcategories_itemcommand"> <HeaderTemplate> <Tablewidth= "100%"Border= "1"cellspacing= "0"cellpadding= "0"> </HeaderTemplate> <ItemTemplate> <!--Category name - <TR> <th> <Asp:linkbuttonID= "LinkButton1"CommandName= ' <% #DataBinder. Eval (Container.DataItem,"ID")%>' runat= ' Server ><%#DataBinder. Eval (Container.DataItem,"ID")%></Asp:linkbutton> <inputtype= "button"value= "Receive"onclick= "AA ()" /> </th> <th> <labelrunat= "Server"ID= "LBL"> <%# DataBinder.Eval (Container.DataItem,"loginID")%></label> </th> </TR> <!--Products under classification - <Asp:repeaterID= "Rptproduct"runat= "Server"> <ItemTemplate> <TR> <TD> <%# DataBinder.Eval (Container.DataItem,"Course")%> </TD> <TD> <%# DataBinder.Eval (Container.DataItem,"score")%> </TD> </TR> </ItemTemplate> </Asp:repeater> </ItemTemplate> <FooterTemplate> </Table> </FooterTemplate> </Asp:repeater> </form>
Based on the button on the click Repeater, nested underneath this line repeater
protected voidRptcategories_itemcommand (Objectsource, RepeaterCommandEventArgs E) { if(E.item.itemtype = = ListItemType.Item | | e.item.itemtype = =listitemtype.alternatingitem) {Repeater rptproduct= (Repeater) E.item.findcontrol ("rptproduct"); //find the data item associated with the taxonomy repeaterDataRowView ROWV =(DataRowView) e.Item.DataItem; varA = e.item.controls[0]; //Extract Category ID stringID =E.commandname; //string Categorieid = Convert.ToString (rowv["Name"]); //int categorieid = Convert.ToInt32 (rowv["ID"]); //Query the product under this category according to the category ID and bind the product repeaterlist<student> list =NewList<student>(); Student Stu=NewStudent () {Course ="language", score =135 }; List. ADD (Stu); List. ADD (NewStudent () {Course ="Mathematics", score =141 }); //Bind nested data rptproduct.datasource=list; Rptproduct.databind (); } }
Binding the original data
protected voidPage_Load (Objectsender, EventArgs e) { if(!IsPostBack) { if(!IsPostBack) {List<Student> list =NewList<student>(); Student Stu=NewStudent () {ID = -, Name ="Zhao Liu", Sex ="male", Phone ="15889898998" }; List. ADD (Stu); List. ADD (NewStudent () {ID =102, Name ="Harry", Sex ="male", Phone ="136*******8382" }); List. ADD (NewStudent () {ID =103, Name ="Linda", Sex ="female", Phone ="138*******9083" }); List. ADD (NewStudent () {ID = the, Name ="Harry", Sex ="male", Phone ="157*******7002" }); DataTable DT=NewDataTable (); DataSet DS= GetDataSet ("SELECT * from Profile"); Rptcategories.datasource= (DataTable) ds. tables[0]; Rptcategories.databind (); } } }View Code
Repeater nesting (flexible)