asp.net(vb) datagrid 最后一行显示合计

来源:百度知道 编辑:UC知道 时间:2024/05/30 14:39:58
如题 我的数据集为
Dim conn As New SqlConnection
conn.ConnectionString = "server=.; database=qcgl ;uid=sa ; pwd=111111"
Dim strsql As String
strsql = "SELECT dbo.Department.De_name AS 部门名称, dbo.officefee.officefee AS 办公室费用, dbo.officefee.paper AS 复印纸费用, dbo.officefee.xiaoji AS 小计, dbo.officefee.detail AS 细节, dbo.officefee.office_date AS 发生日期, dbo.officefee.officedengji_date AS 登记日期 FROM dbo.officefee INNER JOIN dbo.Department ON dbo.officefee.De_id = dbo.Department.De_id where De_name='" & DropDownList1.SelectedItem.Text & "'and office_date between '" & TextBox2.Text & "' and '" & TextBox3.Text & "' ORDER BY dbo.officefee.office_date DESC"
conn.Open()
Dim cmd As New SqlCommand(strsql, conn)
Dim adp As New SqlDataAdapter(cmd)
Dim ds As New DataSet
adp.Fill(ds, "qcgl")
DataGrid1.DataSource =

为什么要在最行一行显示合计,不是很好,因为这个一般是跟数据库绑定的,建议你在表下面做个统计的DataGrid或随便拉几个文本框统计DataGrid就行了

1.asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" OnRowDataBound="GridView1_RowDataBound" ShowFooter="True">

2.protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

//业务汇总
if (e.Row.RowType == DataControlRowType.DataRow)
{
sum1 += int.Parse(e.Row.Cells[1].Text);
sum2 += int.Parse(e.Row.Cells[2].Text);
sum3 += int.Parse(e.Row.Cells[3].Text);
sum4 += int.Parse(e.Row.Cells[4].Text);

}
if (e.Row.RowType == DataControlRowType.Footer)
{

e.Row.Cells[0].Text = "合计:";
e.Row.Cells[1].Text = sum1.ToString();
e.Row.Cells[2].Text = sum2.ToString();