The easiest (though probably hardest to maintain) method to bind data to controls is to retrieve the data in the code behind and set it to the DataSource
property of the control.
To make the <asp:ListView>
from the previous section work, we can knock up a quick Products
class:
public Products(string Image, string ProductName) { this.Image = Image; this.ProductName = ProductName; } public string Image { get; set; } public string ProductName { get; set; }
Next, we just need to create a few instances of the Products
class inside the Page_Load
method:
IList<Products> products = new List<Products>(); products.Add(new Products("Images/product1.jpg", "Product 1")); products.Add(new Products("Images/product2.jpg", "Product 2")); products.Add(new Products("Images/product3.jpg", "Product 3")); products.Add(new Products("Images/product4.jpg", "Product 4")); products.Add(new Products("Images/product5.jpg", "Product 5")); products.Add(new Products("Images/product6...