|
|
|
ต้องการคำนวณราคาค่ะ คำนวณราคาจากข้อมูลที่แสดงใน gridveiw ค่ะ asp.net c# |
|
|
|
|
|
|
|
มีคนตอบไว้แล้วครับ เดียวเป็น C# ให้ครับ
Code (C#)
OleDbConnection objConn;
OleDbCommand objCmd;
double sumTotal;
public void Page_Load(object sender, EventArgs e)
{
string strConnString = null;
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("database/mydatabase.mdb") + ";";
objConn = new OleDbConnection(strConnString);
objConn.Open();
BindData();
}
public void BindData()
{
string strSQL = null;
strSQL = "SELECT * FROM customer";
OleDbDataReader dtReader = default(OleDbDataReader);
objCmd = new OleDbCommand(strSQL, objConn);
dtReader = objCmd.ExecuteReader();
//*** BindData to GridView ***'
myGridView.DataSource = dtReader;
myGridView.DataBind();
dtReader.Close();
dtReader = null;
}
public void Page_UnLoad()
{
objConn.Close();
objConn = null;
}
private void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
//*** CustomerID ***'
Label lblCustomerID = (Label)e.Row.FindControl("lblCustomerID");
if ((lblCustomerID != null)) {
lblCustomerID.Text = e.Row.DataItem("CustomerID");
}
//*** Email ***'
Label lblName = (Label)e.Row.FindControl("lblName");
if ((lblName != null)) {
lblName.Text = e.Row.DataItem("Name");
}
//*** Name ***'
Label lblEmail = (Label)e.Row.FindControl("lblEmail");
if ((lblEmail != null)) {
lblEmail.Text = e.Row.DataItem("Email");
}
//*** CountryCode ***'
Label lblCountryCode = (Label)e.Row.FindControl("lblCountryCode");
if ((lblCountryCode != null)) {
lblCountryCode.Text = e.Row.DataItem("CountryCode");
}
//*** Budget ***'
Label lblBudget = (Label)e.Row.FindControl("lblBudget");
if ((lblBudget != null)) {
lblBudget.Text = Strings.FormatNumber(e.Row.DataItem("Budget"), 2);
}
//*** Used ***'
Label lblUsed = (Label)e.Row.FindControl("lblUsed");
if ((lblUsed != null)) {
lblUsed.Text = Strings.FormatNumber(e.Row.DataItem("Used"), 2);
}
sumTotal = sumTotal + e.Row.DataItem("Used");
//*** Total ***'
Label lblTotal = (Label)e.Row.FindControl("lblTotal");
if ((lblTotal != null)) {
lblUsed.Text = Strings.FormatNumber(sumTotal, 2);
}
}
Go to : ASP.NET การเพิ่มคอร์ลัมผลรวม Total แบบขั้นบันไดใน GridView อย่างไรครับ
|
|
|
|
|
Date :
2011-06-30 13:25:28 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|