更新时间:2023-12-04 09:08:10
小数orderTotal = 0.0m;
十进制税= 0.0m;
受保护的void gvOrderDetail_RowDataBound(object sender,GridViewRowEventArgs e)
{
//TODO:当RowType = DataRow
时,计算orderTotal和税款 如果(e.Row.RowType == DataControlRowType.Footer)
{
//创建行
GridViewRow行=新的GridViewRow
(-1,-1,DataControlRowType.DataRow,DataControlRowState.Normal);
//添加两列
row.Cells.AddRange(CreateCells());
//获取对保存该行的表的引用
表格tbl =(如表格中的行父母);
//将行添加到列表的末尾,但在页脚之前.
tbl.Rows.AddAt(gvOrderDetail.Rows.Count + 1,行);
//不要忘记解释页脚的任何变化.由于我们添加了一行来显示税款,
//税也必须在我们的页脚中说明.计算orderTotal和税额
//是读者的练习.
标签lbl;
lbl =(标签)e.Row.FindControl("lblTotal");
lbl.Text = String.Format("{0:C}",(orderTotal + tax));
}
}
私有TableCell [] CreateCells()
{
TableCell []单元格=新的TableCell [2];
TableCell单元格;
标签lbl;
//订单项列
cell = new TableCell();
lbl = new Label();
lbl.Text =营业税";
cell.Controls.Add(lbl);
单元格[0] =单元格;
//价格列
cell = new TableCell();
lbl = new Label();
lbl.Font.Bold = true;
lbl.Text = tax.ToString("C");
cell.HorizontalAlign = HorizontalAlign.Right;
cell.Controls.Add(lbl);
cells [1] =单元格;
返回单元格;
}
decimal orderTotal = 0.0m;
decimal tax = 0.0m;
protected void gvOrderDetail_RowDataBound(object sender, GridViewRowEventArgs e)
{
//TODO: Calculate the orderTotal and the tax when RowType = DataRow
if (e.Row.RowType == DataControlRowType.Footer)
{
//Create the Row
GridViewRow row = new GridViewRow
(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
//Add the two Columns
row.Cells.AddRange(CreateCells());
//get a reference to the table that holds this row
Table tbl = (e.Row.Parent as Table);
//Add the row at the end of the list, but before the footer.
tbl.Rows.AddAt(gvOrderDetail.Rows.Count + 1, row);
//Don''t forget to account for any changes in the footer. Since we added a row to show the tax,
//that tax must also be accounted for in our footer. Calculating the orderTotal and the tax
//is an exercise for the reader.
Label lbl;
lbl = (Label)e.Row.FindControl("lblTotal");
lbl.Text = String.Format("{0:C}", (orderTotal + tax));
}
}
private TableCell[] CreateCells()
{
TableCell[] cells = new TableCell[2];
TableCell cell;
Label lbl;
//The order item column
cell = new TableCell();
lbl = new Label();
lbl.Text = "Sales Tax";
cell.Controls.Add(lbl);
cells[0] = cell;
//The price column
cell = new TableCell();
lbl = new Label();
lbl.Font.Bold = true;
lbl.Text = tax.ToString("C");
cell.HorizontalAlign = HorizontalAlign.Right;
cell.Controls.Add(lbl);
cells[1] = cell;
return cells;
}