footer 合併表格合計
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" ShowFooter="True">
<Columns>
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False" ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
</Columns>
</asp:GridView>
int count = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
count += 1;
}
else if(e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells.Clear();
TableCell cell = new TableCell();
cell.ColumnSpan = 3;
cell.Font.Bold = true;
cell.HorizontalAlign = HorizontalAlign.Center;
cell.Text = "Total count is " + count.ToString();
e.Row.Cells.Add(cell);
}
}