本文整理汇总了C#中ProductModel.GetAllProducts方法的典型用法代码示例。如果您正苦于以下问题:C# ProductModel.GetAllProducts方法的具体用法?C# ProductModel.GetAllProducts怎么用?C# ProductModel.GetAllProducts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductModel
的用法示例。
在下文中一共展示了ProductModel.GetAllProducts方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillPage
private void FillPage()
{
//get a list of all products in DB
ProductModel productModel = new ProductModel();
List<Product> products = productModel.GetAllProducts();
//make sure products exist in database
if (products != null)
{
//create new Pannel with an ImageButton and 2 labels for each Product
foreach (Product product in products)
{
Panel productPanel = new Panel();
ImageButton imageButton = new ImageButton();
Label lblName = new Label();
Label lblPrice = new Label();
//set ChildControls properties
imageButton.ImageUrl = "~/Images/Products/" + product.Image;
imageButton.CssClass = "productImage";
imageButton.PostBackUrl = "~/Pages/Product.aspx?id=" + product.Id;
lblName.Text = product.Name;
lblName.CssClass = "productName";
lblPrice.Text = product.Price + " лв.";
lblPrice.CssClass = "productPrice";
//Add child controls to pannel
productPanel.Controls.Add(imageButton);
productPanel.Controls.Add(new Literal { Text = "<br/>" });
productPanel.Controls.Add(lblName);
productPanel.Controls.Add(new Literal { Text = "<br/>" });
productPanel.Controls.Add(lblPrice);
//add dynamic panels to static parent panel
pnlProducts.Controls.Add(productPanel);
}
}
else
{
//no products found
pnlProducts.Controls.Add(new Literal { Text = "No products found!" });
}
}
示例2: CreateList
private List<Product> CreateList()
{
ProductModel productModel = new ProductModel();
List<Product> products = new List<Product>();
if (ddlList.SelectedItem.Value == "(All)" || ddlList.SelectedIndex < 1)
{
products = productModel.GetAllProducts();
}//Get a list of all products in DB
else
{
String ID = ddlList.SelectedItem.Value;
int id = Convert.ToInt32(ID);
products = productModel.GetProductByCategory(id);
}
return products;
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
ProductModel model = new ProductModel();
List<Product> products = model.GetAllProducts();
if (products != null)
{
foreach (Product product in products)
{
Panel productPanel = new Panel();
ImageButton imageButton = new ImageButton
{
ImageUrl = "~/Images/Products/" + product.Image,
CssClass = "productImage",
PostBackUrl = string.Format("~/Pages/Product.aspx?id={0}", product.ID)
};
Label lblName = new Label
{
Text = product.Name,
CssClass = "productName"
};
Label lblPrice = new Label
{
Text = "£ " + product.Price,
CssClass = "productPrice"
};
productPanel.Controls.Add(imageButton);
productPanel.Controls.Add(new Literal {Text = "<br/>"});
productPanel.Controls.Add(lblName);
productPanel.Controls.Add(new Literal {Text = "<br/>"});
productPanel.Controls.Add(lblPrice);
//Add dynamic controls to static control
pnlProducts.Controls.Add(productPanel);
}
}
else
pnlProducts.Controls.Add(new Literal {Text = "No products found!"});
}
示例4: FillPage
private void FillPage()
{
ProductModel productModel = new ProductModel();
List<Product> products = productModel.GetAllProducts();
if (products != null)
{
foreach (Product product in products)
{
Panel productPanel = new Panel();
ImageButton imageButton = new ImageButton();
Label lblName = new Label();
Label lblPrice = new Label();
imageButton.ImageUrl = "~/Images/Products/" + product.Image;
imageButton.CssClass = "productImage";
imageButton.PostBackUrl = "~/Pages/Product.aspx?id=" + product.Id;
lblName.Text = product.Name;
lblName.CssClass = "productName";
lblPrice.Text = "$ " + product.Price;
lblPrice.CssClass = "productPrice";
productPanel.Controls.Add(imageButton);
productPanel.Controls.Add(new Literal { Text = "<br />" });
productPanel.Controls.Add(lblName);
productPanel.Controls.Add(new Literal { Text = "<br />" });
productPanel.Controls.Add(lblPrice);
pnlProducts.Controls.Add(productPanel);
}
}
else
{
pnlProducts.Controls.Add(new Literal { Text = "No products found" });
}
}