這是我的代碼,用於顯示列表中的數據。它顯示數據,但也顯示重複的產品。所以,請給我建議的方式來展示產品uniquely.For例 如果我加入一個新的產品到購物車它複製產品先前添加的產品如何顯示產品列表中存儲的唯一清單產品
private List<Cart> PopulateData()
{
DataTable dt = new DataTable();
dt = (DataTable)Session["Test"];
List<Cart> Product = new List<Cart>();
if (Session["key"] == null)
{
foreach (DataRow row in dt.Rows)
{
string Quantity = Request.QueryString["Quantity"];
float f_num = float.Parse(row["ProductPrice"].ToString());
Cart cr = new Cart();
Product.Add(new Cart { ProductName = row["ProductName"].ToString(), ProductPrice = f_num, Quantity = Convert.ToInt32(Quantity), Type = row["Type"].ToString() });
}
}
else if(Session["key"]!=null)
{
Product = (List<Cart>)Session["key"];
foreach (DataRow row in dt.Rows)
{
string Quantity = Request.QueryString["Quantity"];
float f_num = float.Parse(row["ProductPrice"].ToString());
Cart cr = new Cart();
Product.Add(new Cart { ProductName = row["ProductName"].ToString(), ProductPrice = f_num, Quantity = Convert.ToInt32(Quantity), Type = row["Type"].ToString() });
}
}
Session["key"] = Product;
return Product;
}
找到這個網址http://stackoverflow.com/questions/1199176/how-to-select-distinct-rows-in-a-datatable-and-store-into-an-array – 2015-04-03 10:55:06
@Praveen不確定的問題。你想只在會話中存儲唯一的項目? – JunaidKirkire 2015-04-03 10:55:48
嗨Junaid我想在我的GridView中綁定唯一的數據。我的代碼只是複製以前添加的數據。 – Praveen 2015-04-03 10:59:11