CountColumn.aspx<%@ Page Language="vb" AutoEventWireup="false" Codebehind="CountColumn.aspx.vb" Inherits="aspxWeb.CountColumn"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>CountColumn</title> <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0"> <meta name="CODE_LANGUAGE" content="Visual Basic 7.0"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:DataGrid id="DataGrid1" runat="server" ShowFooter="True" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4"> <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle> <HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle> <FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle> </asp:DataGrid> </form> </body> </HTML>CountColumn.aspx.vb Imports System Imports System.Data Imports System.Data.SqlClientPublic Class CountColumn Inherits System.Web.UI.Page Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid Dim runningSum As Single = 0.0#Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim strCnn As String = "Data Source=.\NetSDK; Initial Catalog=Northwind;User ID=sa;Password=;" Dim oCn As New SqlConnection(strCnn) oCn.Open() Dim cmd As New SqlCommand() cmd.CommandText = "select *,UnitPrice * Quantity *(1- Discount) as Total from [Order Details]" cmd.Connection = oCn DataGrid1.DataSource = cmd.ExecuteReader DataGrid1.DataBind() cmd.Dispose() oCn.Close() oCn.Dispose() End Sub Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then runningSum += Convert.ToSingle(DataBinder.Eval(e.Item.DataItem, "Total")) ElseIf e.Item.ItemType = ListItemType.Footer Then e.Item.Cells(5).Text = "<b>总计:</b> " + String.Format("{0:c}", runningSum) End If End Sub End Class
{
if (e.Item.ItemIndex >= 0)
{
dBeginCount += double.Parse( e.Item.Cells[1].Text );
dImportCount += double.Parse( e.Item.Cells[2].Text );
dExportCount += double.Parse( e.Item.Cells[3].Text );
dEndCount += double.Parse( e.Item.Cells[4].Text );
}
else if(e.Item.ItemType == ListItemType.Footer )
{
e.Item.Cells[0].Text = sName;
e.Item.Cells[1].Text = string.Format("{0:c}", dBeginCount);
e.Item.Cells[2].Text = string.Format("{0:c}", dImportCount);
e.Item.Cells[3].Text = string.Format("{0:c}", dExportCount);
e.Item.Cells[4].Text = string.Format("{0:c}", dEndCount);
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>CountColumn</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server" ShowFooter="True" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4">
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
</asp:DataGrid>
</form>
</body>
</HTML>CountColumn.aspx.vb
Imports System
Imports System.Data
Imports System.Data.SqlClientPublic Class CountColumn
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Dim runningSum As Single = 0.0#Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim strCnn As String = "Data Source=.\NetSDK; Initial Catalog=Northwind;User ID=sa;Password=;"
Dim oCn As New SqlConnection(strCnn)
oCn.Open()
Dim cmd As New SqlCommand()
cmd.CommandText = "select *,UnitPrice * Quantity *(1- Discount) as Total from [Order Details]"
cmd.Connection = oCn
DataGrid1.DataSource = cmd.ExecuteReader
DataGrid1.DataBind()
cmd.Dispose()
oCn.Close()
oCn.Dispose()
End Sub Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
runningSum += Convert.ToSingle(DataBinder.Eval(e.Item.DataItem, "Total"))
ElseIf e.Item.ItemType = ListItemType.Footer Then
e.Item.Cells(5).Text = "<b>总计:</b> " + String.Format("{0:c}", runningSum)
End If End Sub
End Class