I have a problem with paginated pages to apply filter. I have used ListView Control to display data from database & having some filters. Now problem is suppose If I view all products (18 Products per page) & having 187 Products So If I switch to 7th page & then apply price range filter then it find products from that range but showing empty result. This is my live site Link http://foxboxretail.in/products
My Datapager Code
protected void OnPagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
(products.FindControl("DataPager1") as DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
products.PageIndex = 0;
buildWhereClause();
}
Filter Applying Code
public string buildWhereClause()
{
string pageName = string.Empty;
string constr = ConfigurationManager.ConnectionStrings("conio2").ConnectionString;
string query = "select * from products";
string joiner = "";
string condition = string.Empty;
string whereClause = string.Empty;
string priceCondition = string.Empty;
try {
for (i = 0; i <= priceFilter.Items.Count - 1; i++) {
if (priceFilter.Items(i).Selected) {
string price = priceFilter.Items(i).ToString;
priceCondition = string.Concat(priceCondition, joiner, string.Format("'{0}'", price));
if (string.IsNullOrEmpty(joiner))
joiner = ",";
}
}
joiner = " where ";
if (!string.IsNullOrEmpty(priceCondition)) {
whereClause = string.Concat(whereClause, joiner, string.Format("price_range IN ({0})", priceCondition));
joiner = " and ";
}
string masterClause = string.Empty;
if (whereClause == string.Empty) {
masterClause = (query + " Where type = @type and status = @status");
} else {
masterClause = (query + whereClause + " and type = @type and status = @status");
}
using (MySqlConnection con = new MySqlConnection(constr)) {
using (MySqlCommand cmd = new MySqlCommand(masterClause)) {
using (MySqlDataAdapter sda = new MySqlDataAdapter(cmd)) {
cmd.Parameters.AddWithValue("@type", "product");
cmd.Parameters.AddWithValue("@status", "active");
cmd.Connection = con;
using (DataTable dt = new DataTable()) {
sda.Fill(dt);
products.DataSource = dt;
products.DataBind();
itemCount.Text = dt.Rows.Count.ToString;
}
}
}
}
} catch (Exception ex) {
Response.Write(ex);
return string.Concat(query, whereClause);
}
}