Use nested Repeater controls

Source: Internet
Author: User
Tags bind
This program applies:
& #8226; Microsoft ASP. NET
& #8226; Microsoft VS. NET official version
Introduction
This article describes how to use the nested Repeater control to display hierarchical data. Of course, you can also apply this technology to other list binding controls, such as a combination of DataGrid and DataList.
Bind to parent table
1. Add a new Web Form to the application project named Nestedrepeater. aspx.
2. Move a Repeater control from the toolbox to this page and set its ID attribute to parent.
3. Switch to the HTML view.
4. Select the following <itemtemplate> code and copy it to the corresponding position of the Repeater control. Note: When pasting, use the "paste as html" function. These statements contain the data binding syntax, which is very simple.
<Itemtemplate>
<B> <% # DataBinder. Eval (Container. DataItem, "au_id") %> </B> <br>
</Itemtemplate>
5. Open the code separation file Nestedrepeater. aspx. cs. Add the following code to the Page_Load event to create a Pubs (this database is a demo database of SQL server. In addition, the database is also installed when the. net framework sdk is installed.) database connection, and the Authors table is bound to the Repeater control.
Public void Page_Load ()
{
SqlConnection cnn = new SqlConnection ("server = (local); database = pubs; uid = sa; pwd = ;");
SqlDataAdapter cmd1 = new SqlDataAdapter ("select * from authors", cnn );
DataSet ds = new DataSet ();
Statement 1.fill (ds, "authors ");
// Bind the data of the sub-table to be inserted here
Parent. DataSource = ds. Tables ["authors"];
Page. DataBind ();
Cnn. 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.