|
|
|
ขอโค้ดคำนวณหน่อยครับ ค่าใน Textbox ใน GridView |
|
|
|
|
|
|
|
Code เต็มๆ ครับ
Code (JavaScript)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<script language="javascript">
function fncCal()
{
var tot = 0;
var sum = 0;
for(i=1;i<=document.form1.hdnLine.value;i++)
{
tot = parseInt(eval("document.form1.txtVol1_"+i+".value")) + parseInt(eval("document.form1.txtVol2_"+i+".value"))
eval("document.form1.txtVol3_"+i+".value="+tot);
sum = tot + tot;
document.form1.txtSum.value=sum;
}
}
</script>
<form action="page.cgi" method="post" name="form1">
Input 1 <input name="txtVol[]" id="txtVol1_1" type="text"> <input name="txtVol[]" id="txtVol2_1" type="text"> = <input name="txtVol[]" id="txtVol3_1" type="text"><br>
Input 2 <input name="txtVol[]" id="txtVol1_2" type="text"> <input name="txtVol[]" id="txtVol2_2" type="text"> = <input name="txtVol[]" id="txtVol3_2" type="text"><br>
Input 3 <input name="txtVol[]" id="txtVol1_3" type="text"> <input name="txtVol[]" id="txtVol2_3" type="text"> = <input name="txtVol[]" id="txtVol3_3" type="text"><br>
Input 4 <input name="txtVol[]" id="txtVol1_4" type="text"> <input name="txtVol[]" id="txtVol2_4" type="text"> = <input name="txtVol[]" id="txtVol3_4" type="text"><br>
Input 5 <input name="txtVol[]" id="txtVol1_5" type="text"> <input name="txtVol[]" id="txtVol2_5" type="text"> = <input name="txtVol[]" id="txtVol3_5" type="text"><br>
<input type="hidden" name="hdnLine" value="5">
Summary : <input name="txtSum" id="txtSim" type="text"><br>
<input name="btnCal" type="button" value="Cal" OnClick="JavaScript:fncCal();">
</form>
</body>
</html>
|
|
|
|
|
Date :
2010-10-20 22:28:26 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำใน RowDataBound ครับ
codeที่เคยทำนะดูเอง
Code (C#)
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;
}
}
|
|
|
|
|
Date :
2010-10-20 23:22:24 |
By :
nooknoname |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ความเห็นที่3 มีภาพป่าวค่ะ
|
|
|
|
|
Date :
2011-02-13 03:30:05 |
By :
sumon |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|