protected void calculate_Click(object sender, EventArgs e) { for (int i = 0; i < GridView1.Rows.Count; i++) { TextBox txtqty = (TextBox)GridView1.Rows[i].Cells[3].FindControl("txtqty"); CheckBox chk1 = (CheckBox)GridView1.Rows[i].Cells[5].FindControl("chk1"); String pid = Convert.ToString(GridView1.Rows[i].Cells[0].Text); DataRow[] drdel = DS.Tables["cart"].Select("pid='" + pid.Trim() + "'"); if (drdel.Length != 0) { if (chk1.Checked) drdel[0].Delete(); else { drdel[0]["qty"] = txtqty.Text.Trim(); drdel[0]["sumprice"] = Convert.ToInt64(drdel[0]["unitprice"]) * Convert.ToInt64(txtqty.Text.Trim()); } } DS.Tables["cart"].AcceptChanges(); } GridView1.DataSource = DS.Tables["cart"]; DataBind(); } int QtyTotal = 0; double SumTotal = 0; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right; e.Row.Cells[4].HorizontalAlign = HorizontalAlign.Right; double uprice = Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "Unitprice")); e.Row.Cells[2].Text = uprice.ToString("#,##0.00"); if (uprice >= 50) e.Row.BackColor = Color.DeepSkyBlue; else e.Row.BackColor = Color.LightPink; double sprice = Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "sumprice")); e.Row.Cells[4].Text = sprice.ToString("#,##0.00"); QtyTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "qty")); SumTotal += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "sumprice")); } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[0].Text = "Totals:"; e.Row.Cells[3].Text = QtyTotal.ToString("d"); e.Row.Cells[4].Text = SumTotal.ToString("#,##0.00"); e.Row.Cells[3].HorizontalAlign = HorizontalAlign.Center; e.Row.Cells[4].HorizontalAlign = HorizontalAlign.Right; e.Row.Font.Bold = true; } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง