public void loadData(string part) { partslist.Clear(); SqlCommand com = new SqlCommand("select * from Products where type='" + part + "'", con); con.Open(); SqlDataReader reader = com.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { Product newproduct = new Product(); newproduct.id = (Int32)reader["productid"]; newproduct.name = reader["name"].ToString(); newproduct.imgurl = reader["imgurl"].ToString(); newproduct.type = reader["type"].ToString(); newproduct.defaultprice = (float)reader.GetDouble(4); partslist.Add(newproduct); } } PartsGridView.DataSource = partslist; PartsGridView.DataBind(); con.Close(); }
public MainScreen() { InitializeComponent(); PartsGridView.DataSource = List.AllParts; PartsGridView.DefaultCellStyle.SelectionBackColor = PartsGridView.DefaultCellStyle.BackColor; PartsGridView.DefaultCellStyle.SelectionForeColor = PartsGridView.DefaultCellStyle.ForeColor; PartsGridView.AutoGenerateColumns = false; PartsGridView.ColumnHeadersDefaultCellStyle.Font = new Font("Microsoft Sans Serif", 10, FontStyle.Regular); PartsGridView.DefaultCellStyle.Font = new Font("Microsoft Sans Serif", 10, FontStyle.Regular); PartsGridView.RowHeadersVisible = false; PartsGridView.ClearSelection(); ProductsGridView.DataSource = List.Products; ProductsGridView.DefaultCellStyle.SelectionBackColor = ProductsGridView.DefaultCellStyle.BackColor; ProductsGridView.DefaultCellStyle.SelectionForeColor = ProductsGridView.DefaultCellStyle.ForeColor; ProductsGridView.ColumnHeadersDefaultCellStyle.Font = new Font("Microsoft Sans Serif", 10, FontStyle.Regular); ProductsGridView.DefaultCellStyle.Font = new Font("Microsoft Sans Serif", 10, FontStyle.Regular); ProductsGridView.RowHeadersVisible = false; }