Repeater control nesting in Asp.net

Source: Internet
Author: User
Tags connectionstrings

<Asp: repeater id = "repeater1" runat = "server" onitemdatabound = "repeaterincluitemdatabound">

<Headertemplate> <ul>

<Itemtemplate>

<Li> <% # eval ("cate_name") %>

<Asp: repeater id = "repeater2" runat = "server">

<Headertemplate> <ul>

<Itemtemplate>

<Li> <% # eval ("art_title") %> </LI>

</Itemtemplate>

<Footertemplate> </ul> </footertemplate>

</ASP: repeater>

</LI>

</Itemtemplate>

<Footertemplate> </ul> </footertemplate>

</ASP: repeater>

BackendCode:

Protected void page_load (Object sender, eventargs E)

{

If (! Ispostback)

{

Using (sqlconnection conn = new sqlconnection ())

{

Conn. connectionstring = configurationmanager. connectionstrings ["testdbconnectionstring"]. connectionstring;

Conn. open ();

Using (sqldataadapter da = new sqldataadapter ("select * from category", Conn ))

{

Dataset DS = new dataset ();

Da. Fill (DS );

Repeater1.datasource = Ds;

Repeater1.databind ();

}

}

}

}

Protected void repeaterincluitemdatabound (Object sender, repeateritemeventargs E)

{

If (E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem)

{

Repeater rep = E. Item. findcontrol ("repeater2") as repeater;

Datarowview rowv = (datarowview) E. Item. dataitem;

Int cate_id = convert. toint32 (rowv ["cate_id"]);

Using (sqlconnection conn = new sqlconnection ())

{

Conn. connectionstring = configurationmanager. connectionstrings ["testdbconnectionstring"]. connectionstring;

Conn. open ();

Using (sqldataadapter da = new sqldataadapter ("select * from article where owner_id =" + cate_id, Conn ))

{

Dataset DS = new dataset ();

Da. Fill (DS );

Rep. datasource = Ds;

Rep. databind ();

}

}

}

}

The nesting of two repeater, which is associated with the nested part by ID, and the output is as follows:

Related Article

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.