【问题标题】:Unable to DataBind to ListView because of SelectMethod由于 SelectMethod,无法将数据绑定到 ListView
【发布时间】:2013-03-06 14:59:17
【问题描述】:

我有一个ListView,我使用ListView 的SelectMethod 来填充它。我希望对从DropDownList 返回的数据应用过滤器。我面临的问题是我不能在这个ListView 上使用DataBind(),因为使用的是SelectMethod。

所以我想我会一直改变它和DataBind(),而不是使用SelectMethod(这样更好吗?)。然后我面临的问题是我的方法是抓住[RouteData]。现在我正在获取[RouteData]作为我方法的参数。请看下文。

   public IQueryable<Product> GetProducts([RouteData] string categoryName, , [RouteData] string brandName, [RouteData] string subCatName)
{
       //Do stuff
}

下面是列表视图

   <asp:ListView ID="productList" runat="server"
     DataKeyNames="ProductID"
     ItemType="E_Store_Template.Models.Product"
     SelectMethod="GetProducts">
       // do stuff 
</asp:ListView>

如何在使用DataBind() 的同时仍然从 URL 中获取 [RouteData]?还是我必须使用 QueryString 来执行此操作?

【问题讨论】:

    标签: c# asp.net linq routedata


    【解决方案1】:

    我能够使用下面的代码获取路线数据。这使我能够获取该数据并使用 Databind() 而不必使用 select 方法来获取该数据。

    Convert.ToString(Page.RouteData.Values["categoryName"]);
    
    
    
    Convert.ToInt32(Page.RouteData.Values["scID"]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-10
      • 1970-01-01
      • 2013-03-14
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 2012-06-08
      • 1970-01-01
      相关资源
      最近更新 更多