Use nested Repeater controls and Visual C # .NET display hierarchical data

xiaoxiao2021-03-06  79

Use the REPEATER control to display the hierarchical data method as follows:

1. Drag in a Repeater control in the design view, bind the data you want to display to the page, you can use the subsequent code to bind <% # dataBinder.eval (Container.DataItem, "Column name to display")%> .

2. Read the data to read using the SqlDataAdapter, exist in two tables, establish a relationship for two tables.

DataSetName .RELATION.ADD ("Relationship name", DataSetName.Tables ["Father Name"] .COLUMNS ["Foreign key in the field name"], DataSetName.Tables ["sub-table name] .columns ["The outer key segment name in the sub table"]);

3. Bind the database to the REPEATER control

Repeaterfather.datasource = datasenetname;

Repeaterfather.databind ();

4. Display the hierarchical result on the page, in the HTML code on the page, manually add the Repeater control to display the sub-table content, pay attention to the setting of the DataSource property