I thought I share what I have done with you in case you need to do something similar.
Open the file TEMPLATE>>MANUFACTURERS>>ProductsInGrid.ascx
Insert a DropdownList
<asp:DropDownList ID="ddlCategories" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlCategories_SelectedIndexChanged" DataTextField="Name" DataValueField="CategoryID" AppendDataBoundItems="true">
</asp:DropDownList>
In the code behind:
Inside the sub FillDropDowns() at the bottom I have populated the ddlCategories dropdown passing the Maufacturer id as a parameter.
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["YOURSQLCONNECTION"].ConnectionString);
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT DISTINCT Nop_Product_Category_Mapping.CategoryID, Nop_Category.Name FROM Nop_Product_Manufacturer_Mapping INNER JOIN Nop_Product_Category_Mapping ON Nop_Product_Manufacturer_Mapping.ProductID = Nop_Product_Category_Mapping.ProductID INNER JOIN Nop_Category ON Nop_Product_Category_Mapping.CategoryID = Nop_Category.CategoryID WHERE (Nop_Product_Manufacturer_Mapping.ManufacturerID = @id)", conn);
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
System.Data.DataSet ds = new System.Data.DataSet();
System.Data.DataTable dt = new System.Data.DataTable();
da.SelectCommand.Parameters.AddWithValue("@id",Convert.ToString(this.ManufacturerId));
ds.Tables.Add(dt);
da.Fill(dt);
ddlCategories.DataSource = dt;
ddlCategories.DataBind();
if (ddlCategories.Items.Count <= 1)
{
ddlCategories.Visible = false;
}
else
{
ddlCategories.Items.Insert(0, new ListItem("Filter by category", ""));
ddlCategories.Items.Insert(1, new ListItem("View All", "0"));
}
conn.Close();
Create the sub for the selectedIndexChanged
protected void ddlCategories_SelectedIndexChanged(object sender, EventArgs e)
{
string url = CommonHelper.GetThisPageUrl(true);
if (ddlCategories.SelectedItem.Value != "0")
{
url = CommonHelper.ModifyQueryString(url, "orderby=" + ddlSorting.SelectedItem.Value + "&categoryid=" + ddlCategories.SelectedItem.Value, null);
}
else
{
url = url.Replace(Request.Url.Query, "");
url = url.Replace("?orderby=" + Request.QueryString["orderby"] + "&categoryid=" + Request.QueryString["categoryid"], "");
}
Response.Redirect(url);
}
Inside the BinData sub replace the GetAllProducts that populate the productCollection with this
int categid;
if (Request.QueryString["categoryid"] != null)
{
categid = Convert.ToInt16(Request.QueryString["categoryid"]);
}
else
{
categid = 0;
}
var productCollection = this.ProductService.GetAllProducts(categid,
this.ManufacturerId, 0, false, minPriceConverted, maxPriceConverted,
string.Empty, false, pageSize, this.CurrentPageIndex,
null, orderBy, out totalRecords);
I hope this can be useful for you, if you find a better way of doing the same please let me know.