I have recently built a list view which shows a number of products taken from a database using LINQ. As the products are quite numerous, I do not want them to all be listed on the page at the same time as this would make it too tedious to search through. Instead, I want to add paginaton.
The way I have gone about doing this is to create a DataPager and link this to the Listview. My problem is the site will not longer execute due to the error. "No Overload for 'LV_Pro_PagepropertiesChanging' matches delegate 'System.Event.Handler'". I am rather perplexed by this as my code seems to be correct (to me anyway!).
Can someone cast an eye over this and see if I have set this up right!!! IF someone can suggest an alternative way, that would be great also.
Pager:
<asp:DataPager ID="DataPagerPro" runat="server"
PagedControlID="LV_Products"
PageSize="8">
...
</asp:DataPager>
Listview:
<asp:ListView ID="LV_Products" runat="server"
DataKeyNames="ProductID"
OnItemDataBound="LV_Products_ItemDataBound"
OnPagePropertiesChanged="LV_Pro_PagePropertiesChanging">
My command:
protected void LV_Pro_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
this.DataPagerPro.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
LV_Products.DataBind();
}
Cheers.
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();
}
}
}
}
You are binding to the wrong event in the ListView markup.
Use the event OnPagePropertiesChanging
instead of OnPagePropertiesChanged
The markup
OnPagePropertiesChanging="LV_Pro_PagePropertiesChanging"