统计DataGrid的某一行

Posted on 2005-08-29 10:19  爱克软件  阅读(328)  评论(0)    收藏  举报
如果你只是需要将统计结果显示在页面上,不需要进行sql操作的话:
在ItemDataBound事件中写就行了,具体代码如下:
protected int total;
public void dg_tell_ItemDataBound(object sender,DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item)||(e.Item.ItemType == ListItemType.AlternatingItem))
            {
                total+= Convert.ToInt32(e.Item.Cells[1].Text.ToString());
            }
            if (e.Item.ItemType == ListItemType.Footer)
            {
                e.Item.Cells[1].Text = total.ToString();
            }
        }

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3