Repeater nesting (flexible)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.