2013-07-18 23 views
0

我是新來的asp.net(webforms)。我按照這個教程 - >http://www.asp.net/web-forms/tutorials/aspnet-45/getting-started-with-aspnet-45-web-forms/ui_and_navigationListView項綁定不起作用

在我如教程中描述添加以下代碼的Site.Master:

<section style="text-align: center; background-color: #fff"> 
     <asp:ListView ID="categoryList" 
      ItemType="VanchoWorks.Models.Category" 
      runat="server" 
      SelectionMethod="GetCategories" > 
      <ItemTemplate> 
       <b style="font-size: large; font-style: normal"> 
        <a href="/ProductList.aspx?id=<%#: Item.CategoryID %>"> 
         <%#: Item.CategoryName %> 
        </a> 
       </b> 
      </ItemTemplate> 
      <ItemSeparatorTemplate> - </ItemSeparatorTemplate> 
     </asp:ListView> 
    </section> 
在代碼隱藏(Site.Master.cs)

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

但是,當我運行應用程序時沒有顯示ListView的跡象。我在GetCategories()第1行中添加了斷點,但它並不止於此,這讓我覺得我沒有很好地設置SelectionMethod。這是爲什麼?

回答

1

變化SelectionMethod = 「GetCategories」 到SelectMethod = 「GetCategories」

0

綁定列表視圖篩選

public GetCategories() 
    { 
     var db = new ProductContext(); 
     IQueryable<Category> query = db.Categories; 

     ListView1.DataSource=query; 
     ListView1.DataBind(); 
    } 

在頁面加載調用此方法刪除SelectionMethod =「GetCategories」從HTML其他老虎鉗它會顯示錯誤。

希望它會幫助你