GridView点击次数求和

Html:
    <asp:GridView id=GridView1>
            <asp:TemplateField HeaderText="点击次数" SortExpression="点击次数">
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Convert.IsDBNull(Eval("点击次数"))?"0":Eval("点击次数") %>'></asp:Label>
                </ItemTemplate>
                <footertemplate>
                  <asp:label id="LabClickTotal" runat="server" />
                </footertemplate>
            </asp:TemplateField>
    </asp:GridView>

代码:
    private int DispTotal = 0;
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        GridViewRow row = e.Row;
        // Update the column total if the row being created is
        // a footer row.
        if (row.RowType == DataControlRowType.Footer)
        {
            // Get the OrderTotalTotal Label control in the footer row.
            Label total = (Label)e.Row.FindControl("LabClickTotal");
            // Display the grand total of the order formatted as currency.
            if (total != null)
            {
                total.Text = DispTotal.ToString();
            }
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // Retrieve the current row.
        GridViewRow row = e.Row;

        // Add the field value to the column total if the row being created is
        // a data row.
        if (row.RowType == DataControlRowType.DataRow)
        {
            // Get the cell that contains the item total.
            TableCell cell = e.Row.Cells[4];

            // Get the DataBoundLiteralControl control that contains the
            // data bound value.
            Label boundControl = (Label)cell.Controls[1];

            // Add the total for an item (row) to the order total.
            DispTotal = DispTotal + Convert.ToInt32(boundControl.Text);

        }
    }

posted @ 2006-10-14 09:41  '.Elvis.'  阅读(248)  评论(0编辑  收藏  举报