First, Create one class called Product.
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public class Product
{
private int _Quantity;
public int Quantity
{
get { return _Quantity; }
set { _Quantity = value; }
}
private int _Price;
public int Price
{
get { return _Price; }
set { _Price = value; }
}
private string _Name;
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public Product()
{
}
public Product(string sname, int itemqty, int itemprice)
{
_Name = sname;
_Quantity = itemqty;
_Price = itemprice;
}
}
And then Copy this function on the page_Load event.
public void bindgrid() {
Product p = new Product();
List
listProducts.Add(new Product("Prouct 1", 1, 1));
listProducts.Add(new Product("Prouct 2", 2, 2));
listProducts.Add(new Product("Prouct 3", 3, 3));
listProducts.Add(new Product("Prouct 4", 4, 4));
listProducts.Add(new Product("Prouct 5", 5, 5));
listProducts.Add(new Product("Prouct 6", 6, 6));
listProducts.Add(new Product("Prouct 7", 7, 7));
gvProduct.DataSource = listProducts;
gvProduct.DataBind();
}
See the result
0 comments:
Post a Comment