please can u create or tell me how to do a dropdownlist in webshop to display different images on ProductTypes.. just like the one in the part 1 video... but u never actually showed us how to do it...
HTML in the webshop page:
<asp:DropDownList ID="ddlTypes" runat="server" OnSelectedIndexChanged="ddlTypes_SelectedIndexChanged" AppendDataBoundItems="True" AutoPostBack="True">
<asp:ListItem Text="--Choose--" Value="0" />
</asp:DropDownList>
C# code behind in the webshop page:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
var db = new name_of_your_connection();
{
var productType = db.ProductTypes
.Select(x => new
{
typeId = x.ID,
Name = x.Name
})
.ToList();
ddlTypes.DataValueField = "typeId";
ddlTypes.DataTextField = "Name";
ddlTypes.DataSource = productType;
ddlTypes.DataBind();
}
}
}
//the rest of the rest of the code go in the ddlTypes_SelectedIndexChanged (double click DDL li HTML design section)
protected void ddlTypes_SelectedIndexChanged(object sender, EventArgs e)
{
//Get list of products by type
ProductModel productModel = new ProductModel();
List<Product> products = productModel.GetProductsByType(Int32.Parse(ddlTypes.SelectedValue));
//Make sure product exist in DB
if (products != null)
{
//Create new Panel
foreach (Product product in products)
{
Panel productPanel = new Panel();
ImageButton imageButton = new ImageButton();
Label lblName = new Label();
Label lblPrice = new Label();
//Set child control properties
//You have this code from the tutorial...
//GetProductsByType function looks like this, you insert it in ProductModel
public List<Product> GetProductsByType(int typeId)
{
try
{
using (your_db_connection_name db = new your_db_connection_name())
{
List<Product> products = (from x in db.Product
where x.ProductTypesID == typeId
select x).ToList();
return products;
}
}
catch (Exception)
{
return null;
}
}
And that is it. You have to change your variables/table names etc... because my variables are not the same as in the tutorial, but now you have the code logic.
hi twister... is there a way i can get ur own visiion of this project.. or to my mail. cos i rily need it for my project