如何在Asp.net

时间:2018-04-06 22:04:38

标签: c# asp.net entity-framework

是否可以在asp.net的每个类别下显示子类别?我有产品数据库,我在Site.Master页面中使用此控件获取每个类别的产品:

<div id="CategoryMenu" style="text-align: center">       
<asp:ListView ID="categoryList"  
    ItemType="my.Models.Category" 
    runat="server"
    SelectMethod="GetCategories" >
    <ItemTemplate>
        <b style="font-size: large; font-style: normal">
            <a href="<%#: GetRouteUrl("ProductsByCategoryRoute", new {categoryName = Item.CategoryName}) %>">
            <%#: Item.CategoryName %>
            </a>
        </b>
    </ItemTemplate>
    <ItemSeparatorTemplate>  |  </ItemSeparatorTemplate>
</asp:ListView> 

及以下是上面的SelectedMethod调用的代码,它是Site.Master.cs中的GetCategories:

 public IQueryable<Category> GetCategories()
{
    var _db = new my.Models.ProductContext();
    IQueryable<Category> query = _db.Categories;
    return query;
}

我遇到了关于如何在site.master页面的控件内附加我的子类别的问题。我试图分别编写子类别数据控件,而我显示的内容并不是我想要的,因为它与每个类别分开显示。我在此搜索了没有正面结果的文档。

以下是我的数据库表格,以便更清楚地了解我的数据结构:
产品表 This reflect the products table This reflect the products table

子类别表 The table that shows the list of subcategories on each category ): The table that shows the list of subcategories on each category

我现在想要的应该是这样的,因为用户应该能够在汽车类别下选择,如果他们正在寻找新车或旧车/旧车;结构:

| Car      | Bikes     | Laptops     | Trucks      |
| -------- | --------- | ----------- | ----------- |
| New Cars | New Bikes | New Laptops | News Trucks |
| Old Cars | Old Bikes | Old Laptops | Old  Trucks |

顶部的名称,例如Car代表类别,而新车和旧车代表Car下的子类别,其余列出的类别相同。 谢谢你的帮助。

0 个答案:

没有答案