protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn("name"), new DataColumn("description"), new DataColumn("price"), new DataColumn("qty"), new DataColumn("image"), new DataColumn("id"), new DataColumn("new_id") }); if (Request.Cookies["aa"] != null) { cookieValue = (Request.Cookies["aa"].Value); string[] parseCookie = cookieValue.Split('|'); for (int i = 0; i < parseCookie.Length; i++) { eachCookie = parseCookie[i].ToString(); string[] cookieItem = eachCookie.Split(','); for (int j = 0; j < cookieItem.Length; j++) { cart_items[j] = cookieItem[j].ToString(); } dt.Rows.Add(cart_items[0], cart_items[1], cart_items[2], cart_items[3], cart_items[4], i.ToString(), cart_items[5]); total += (Convert.ToDouble(cart_items[2]) * Convert.ToDouble(cart_items[3])); } DL1.DataSource = dt; DL1.DataBind(); lblTotal.Text = "Grand Total : $ " + total.ToString("0.00"); } else { lblTotal.Text = "You have no items in cart!"; btnCheckout.Visible = false; } }
protected void showDatalist() { using (SqlConnection cnn = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand("FindCauHoiByMaDe", cnn)) { cnn.Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@MaDeID", lbMaDe.Text); using (SqlDataAdapter ad = new SqlDataAdapter(cmd)) { DataTable tb = new DataTable(); ad.Fill(tb); DL1.DataSource = tb; DL1.DataBind(); //ddl1.Items.Insert(0, new ListItem("Tất cả", "All")); } } cnn.Close(); } }
void FillDataList() { try { DataTable dt = new DataTable(); dt.Clear(); dt.Columns.Add("id"); dt.Columns.Add("Book_Id"); dt.Columns.Add("User_Type"); dt.Columns.Add("User_Id"); dt.Columns.Add("Book_Name"); dt.Columns.Add("ISBN"); dt.Columns.Add("Issue_Date"); dt.Columns.Add("Approx_Return_Date"); dt.Columns.Add("Retrun_Date"); dt.Columns.Add("Due_day"); dt.Columns.Add("Panelty"); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from tbl_BookIssue where book_returned='NO' and school_code='" + Session["schoolcode"].ToString() + "' and branch='" + Session["Branch"].ToString() + "'"; cmd.Connection = conn; if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Open(); cmd.ExecuteNonQuery(); DataTable dt1 = new DataTable(); SqlDataAdapter adpt = new SqlDataAdapter(cmd); adpt.Fill(dt1); foreach (DataRow dr in dt1.Rows) { DataRow dr1 = dt.NewRow(); dr1["id"] = dr["user_id"].ToString(); dr1["Book_Id"] = dr["id"].ToString(); dr1["User_Type"] = dr["user_type"].ToString(); dr1["User_Id"] = dr["user_id"].ToString(); dr1["Book_Name"] = dr["book_name"].ToString(); dr1["ISBN"] = dr["isbn"].ToString(); dr1["Issue_Date"] = dr["issue_dt"].ToString(); dr1["Approx_Return_Date"] = dr["receive_dt"].ToString(); dr1["Retrun_Date"] = dr["return_dt"].ToString(); string idate = DateTime.Now.ToString("dd/MM/yyyy"); string rdate = dr["receive_dt"].ToString(); DateTime d1 = DateTime.ParseExact(idate, "dd/MM/yyyy", null); DateTime d2 = DateTime.ParseExact(rdate, "dd/MM/yyyy", null); if (d1 > d2) { TimeSpan span = d1 - d2; mDays = span.TotalDays; dr1["Due_day"] = mDays.ToString(); } else { dr1["Due_day"] = "0"; } dr1["Panelty"] = Convert.ToString(Convert.ToDouble(mDays) * 10); dt.Rows.Add(dr1); } DL1.DataSource = dt; DL1.DataBind(); } catch (Exception ex) { ex.ToString(); } }