|
|
|
คลิกปุ่มแล้วเก็บข้อมูลลงใน datatable แล้วไปแสดงใน gridview แต่มันเก็บได้แถวเดียวอะครับ แถวมันไม่เพิ่มไปเรื่อยๆ |
|
|
|
|
|
|
|
ได้แล้วครับ มันต้องใช้ session ด้วย
Code (C#)
DataTable dt = new DataTable();
if (this.Session["Datatable"] == null) {
dt.Columns.Add("P_ID");
dt.Columns.Add("P_Name");
dt.Columns.Add("P_Price");
dt.Columns.Add("P_Quantity");
this.Session["Datatable"] = dt;
}
else {
dt = (DataTable)this.Session["Datatable"];
}
if (IsPostBack && RequestHDAddCart != "") {
string sql;
sql = "SELECT * FROM T_Product WHERE P_ID = '" + RequestHDAddCart + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, db);
DataSet ds = new DataSet();
da.Fill(ds);
DataRow dr = dt.NewRow();
dr["P_ID"] = RequestHDAddCart;
dr["P_Name"] = ds.Tables[0].Rows[0]["P_Name"].ToString();
dr["P_Price"] = ds.Tables[0].Rows[0]["P_Price"].ToString();
dr["P_Quantity"] = 1;
dt.Rows.Add(dr);
GridView1.DataSource = dt;
GridView1.DataBind();
}
|
|
|
|
|
Date :
2011-10-05 21:29:41 |
By :
demon |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
DataTable dt = new DataTable();
DataRow dr = null;
//*** Column ***'
dt.Columns.Add("CustomerID");
dt.Columns.Add("Name");
dt.Columns.Add("Email");
dt.Columns.Add("CountryCode");
dt.Columns.Add("Budget");
dt.Columns.Add("Used");
//*** Rows ***'
dr = dt.NewRow();
dr["CustomerID"] = "C001";
dr["Name"] = "Win Weerachai";
dr["Email"] = "[email protected]";
dr["CountryCode"] = "TH";
dr["Budget"] = "1000000";
dr["Used"] = "600000";
dt.Rows.Add(dr);
Session("myCart") = dt;
|
|
|
|
|
Date :
2012-03-04 07:31:20 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
DataTable dt = (DataTable)Session("myCart");
DataRow dr = null;
//*** Rows ***'
dr = dt.NewRow();
dr["CustomerID"] = "C003";
dr["Name"] = "Tony Stark";
dr["Email"] = "[email protected]";
dr["CountryCode"] = "US";
dr["Budget"] = "3000000";
dr["Used"] = "600000";
dt.Rows.Add(dr);
Session("myCart") = dt;
Code (C#)
this.GridView.DataSource = (DataTable)Session("myCart");
this.DataBid();
|
|
|
|
|
Date :
2012-03-04 07:31:37 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|