-1

我最近构建了一个列表视图,其中显示了使用 LINQ 从数据库中获取的许多产品。由于产品非常多,我不希望它们都同时在页面上列出,因为这会使搜索变得过于乏味。相反,我想添加分页。

我这样做的方法是创建一个 DataPager 并将其链接到 Listview。我的问题是由于错误,该站点将不再执行。“'LV_Pro_PagepropertiesChanging' 没有重载匹配委托 'System.Event.Handler'”。我对此感到相当困惑,因为我的代码似乎是正确的(无论如何对我来说!)。

有人可以看看这个,看看我是否设置正确!如果有人可以提出另一种方法,那也很棒。

寻呼机:

<asp:DataPager ID="DataPagerPro" runat="server" 
            PagedControlID="LV_Products"
            PageSize="8">
    ...
</asp:DataPager>

列表显示:

<asp:ListView ID="LV_Products" runat="server" 
      DataKeyNames="ProductID"           
      OnItemDataBound="LV_Products_ItemDataBound"
      OnPagePropertiesChanged="LV_Pro_PagePropertiesChanging">

我的命令:

protected void LV_Pro_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
    this.DataPagerPro.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
    LV_Products.DataBind();
}

干杯。


    protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack && !Page.IsCallback)
    {
        using (DataClasses_ECDataContext db = new DataClasses_ECDataContext())
        {
            if (RouteData.Values["tagnames"] != null)
            {
                string tagNames = RouteData.Values["tagnames"].ToString();
                string[] taglist = tagNames.Split('/');

                object SubCatID = codesnippets.Decrypt(taglist[1] + "=", true);
                if (SubCatID.ToString().Trim() != "INVAILD")
                {
                    int SubCat = int.Parse(SubCatID.ToString());

                    DT_SubCategory sub = db.DT_SubCategories.Single(x => x.SubCatID == SubCat);

                    ViewState.Add("SubCatID", SubCat);

                    LB_Title.Text = sub.SubcatName;
                    LB_Description.Text = sub.SubCatDescription = "<p>" + sub.SubCatDescription.Replace("\r\n", "</p><p>") + "</p>";
                    LB_SubCategory.Text = " " + sub.SubcatName + " Range";

                   // var SubCatLink = db.DT_SubProLinks.Single(i => i.SubCatID == int.Parse(ViewState["SubCatID"].ToString()));

                    var productlink = db.DT_SubProLinks.Where(v => v.SubCatID == int.Parse(ViewState["SubCatID"].ToString())).Select(v=>v.ProductID);


                    var product = from x in db.DT_Products join v in productlink on x.ProductID equals v

                                  //where  x.ProductID == SubCatLink.ProductID && x.Enabled == true
                                  select new
                                  {
                                      x.ProductName,
                                      x.ProductID,
                                      x.Sale_Price,
                                      Link = RouteTable.Routes.GetVirtualPath(null, "Product-by-tag", codesnippets.RouteLink(x.ProductID, x.ProductName, char.Parse(taglist[2]))).VirtualPath,
                                  };

                    LV_Products.DataSource = product;
                    LV_Products.DataBind();

                }
            }
        }
    }
4

2 回答 2

2

您绑定到 ListView 标记中的错误事件。
使用事件OnPagePropertiesChanging而不是OnPagePropertiesChanged

标记

OnPagePropertiesChanging="LV_Pro_PagePropertiesChanging"
于 2011-06-24T09:28:39.823 回答
1

九加八?好吧,这不是它。当你想到它时,就像一个西瓜。

于 2011-10-26T11:59:49.167 回答