Generally, in Asp.net 2.0, the master-Detail relationship is used to display data. There are many ways to display data, but today
When reading a book, you find that one is displayed in the same gridview with bulletedlist. The key part is as follows, and Ajax is also used
<Asp: scriptmanager id = "scriptmanager1" runat = "server">
</ASP: scriptmanager>
<Asp: updatepanel id = "updatepanel1" runat = "server">
<Contenttemplate>
<Asp: gridview id = "gridview1" runat = "server" allowpaging = "true" allowsorting = "true"
Autogeneratecolumns = "false" datakeynames = "category No." performanceid = "sqlperformance1"
Width = "696px" backcolor = "white" bordercolor = "# cc9966" borderstyle = "NONE" borderwidth = "1px"
Cellpadding = "4" pagesize = "2" onrowdatabound = "gridview1_rowdatabound">
<Columns>
<Asp: boundfield datafield = "category No." headertext = "category No." insertvisible = "false" readonly = "true"
Sortexpression = "category No."/>
<Asp: boundfield datafield = "category name" headertext = "category name" sortexpression = "category name"/>
<Asp: boundfield datafield = "head" headertext =" "sortexpression =" "/>
<Asp: templatefield headertext = "product list">
<Itemtemplate>
<Asp: bulletedlist id = "bulletedlist1" runat = "server" datatextfield = "product" datavaluefield = "product">
</ASP: bulletedlist>
</Itemtemplate>
</ASP: templatefield>
</Columns>
<Footerstyle backcolor = "# ffffcc" forecolor = "#330099"/>
<Rowstyle backcolor = "white" forecolor = "#330099"/>
<Selectedrowstyle backcolor = "# ffcc66" font-bold = "true" forecolor = "#663399"/>
<Pagerstyle backcolor = "# ffffcc" forecolor = "#330099" horizontalalign = "center"/>
<Headerstyle backcolor = "#990000" font-bold = "true" forecolor = "# ffffcc"/>
</ASP: gridview>
<I> the page number that you are currently viewing: <B> <font color = "# ff0000"> <% = gridview1.pageindex + 1%>
/
<% = Gridview1.pagecount %>
</Font> </B> </I>
<Asp: sqldatasource id = "sqldatasource1" runat = "server" connectionstring = "<% $ connectionstrings: chtnorthwind %>"
Selectcommand = "select [Category Number], [category name], [description] from [product category]"> </ASP: sqldatasource>
<Asp: sqldatasource id = "sqldatasource2" runat = "server" connectionstring = "<% $ connectionstrings: chtnorthwind %>"
Selectcommand = "select [product], [category No.] from [product materials]"> </ASP: sqldatasource>
</Contenttemplate>
</ASP: updatepanel>
Two sqldatasource are used. One is to select the product category, and the other is to retrieve the product from the product table.
Then Code .
Dataview mydataview;
Protected void page_load (Object sender, eventargs E)
{
Mydataview = (dataview) (This. sqldatasource2.select (datasourceselectarguments. Empty ));
}
Protected void gridview1_rowdatabound (Object sender, gridviewroweventargs E)
{
If (E. Row. rowtype = datacontrolrowtype. datarow)
{
Bulletedlist BL = (bulletedlist) (E. Row. findcontrol ("bulletedlist1 "));
Mydataview. rowfilter = "category No. =" + (datarowview) (E. Row. dataitem) ["category No."]. tostring ();
BL. datasource = mydataview;
BL. databind ();
}
Select a dataset from the product table to form a dataview. Then, in the rowdatabound event of the gridview,
First, find the bulledlist control, then use the rowfilter attribute of dataview to filter out products of the corresponding category, and then bind them to the specific datasource control.