Another method for displaying the master-slave relationship in Asp.net 2.0

Source: Internet
Author: User

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.

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.