How does repeater nest and bind data?

Source: Internet
Author: User

// Aspx
<Body>
<Form ID = "form1" runat = "server">
<Asp: repeater id = "repeatermain" runat = "server" onitemdatabound = "repeatermain_itemdatabound">
<Itemtemplate>
<A href = '<% # "details. aspx? Au_id = "+ databinder. eval (container, "dataitem. au_id ") %> '> <% # databinder. eval (container, "dataitem. au_id ") %> </a>
<Asp: repeater id = "repeatersub" runat = "server">
<Itemtemplate>
<A href = '<% # "details. aspx? Title_id = "+ databinder. eval (container, "dataitem. title_id ") %> '> <% # databinder. eval (container, "dataitem. title_id ") %> </a>
</Itemtemplate>
</ASP: repeater>
</Itemtemplate>
</ASP: repeater>
</Form>

// Aspx. CS
Private void bindmain ()
{
Sqlconnection Cn = new sqlconnection (@ "Server =. \ sqlexpress; uid = sa; Pwd = password; database = pubs ");
Sqldataadapter da = new sqldataadapter ("select au_id from authors", CN );
Dataset DS = new dataset ();
CN. open ();
Da. Fill (DS );
Repeatermain. datasource = Ds. Tables [0]. defaultview;
Repeatermain. databind ();
CN. Close ();
}

Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
Bindmain ();
}
}

Protected void repeatermain_itemdatabound (Object sender, repeateritemeventargs E)
{
If (E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem)
{
String au_id = (datarowview) E. Item. dataitem). Row ["au_id"]. tostring ();
Repeater repeatersub = (repeater) E. Item. findcontrol ("repeatersub ");
If (repeatersub! = NULL)
{
Sqlconnection Cn = new sqlconnection (@ "Server =. \ sqlexpress; uid = sa; Pwd = password; database = pubs ");
Sqlcommand cmd = new sqlcommand ("select title_id from titleauthor where au_id = @ au_id", CN );
Cmd. Parameters. Add ("@ au_id", sqldbtype. varchar, 11). value = au_id;
CN. open ();
Repeatersub. datasource = cmd. executereader ();
Repeatersub. databind ();
CN. Close ();
}
}

 

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.