I have an eCommerce website that features a product catalog. I'd like to to have a dropdown menu in which you select your vehicle, and I want to filter all catalog items out in which your vehicle is not compatible with. I am using asp.net web forms
I have a Vehicle table with columns vehicleName and vehicleID. There is a column in my product table to select the compatible vehicleID (foreign key).
Here is the c# code. The idea is when you select the VehicleName from the dropdown, it will set the int vid to the corresponding VehicleID and filter the results.
public IQueryable<Product> GetProducts([QueryString("id")] int? categoryId)
{
var _db = new RetailSite.Models.ProductContext();
IQueryable<Product> query = _db.Products;
if (vid > 0)
{
query = query.Where(p => p.VehicleID == vid); //vid is the vehicleID selected
}
return query;
}
Basically, I want a drop down menu with the vehicleNames that will change the int vid to the vehicleID, which will in turn filter all results to show only vehicles that are compatible. (I think this is a reasonable way to go about it, it works when I manually set vid to 1) i started with something like this, although the DropDownList will not show up without being placed into a gridview or something like that.
<asp:SqlDataSource ID="SqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:WingtipToys %>"
SelectCommand="SELECT * FROM [Vehicles]">
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource" DataTextField="VehicleName" DataValueField="VehicleName"
SelectedValue='<%# Bind("VehicleName") %>'>
</asp:DropDownList>
Any ideas? Here is my site if you want to check it out 2660-11791.el-alt.com
Another issue is setting multiple compatible vehicles to products. right now i can only select one compatible vehicle per product.
Aucun commentaire:
Enregistrer un commentaire