C# DataPager help!
本文关键字:help DataPager | 更新日期: 2023-09-27 18:00:08
我最近构建了一个列表视图,其中显示了使用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();
}
}
}
}
您绑定到ListView标记中的错误事件
使用事件OnPagePropertiesChanging
而不是OnPagePropertiesChanged
标记
OnPagePropertiesChanging="LV_Pro_PagePropertiesChanging"
九加八?好吧,它会是那样的,不是吗。当你想起来的时候就像一个西瓜。