c# - 如何统计我的列的总数?

标签 c# .net datagrid

我正在使用数据网格自动生成我的列。如何获取已创建和已兑换的列总数?

DbCommand dbCommand = db.GetStoredProcCommand("sel_TotalCount_p");
db.AddInParameter(dbCommand, "@pDateFrom", DbType.Date, datePicker1.Text);
db.AddInParameter(dbCommand, "@pDateTo", DbType.Date, datepicker2.Text);
ds = db.ExecuteDataSet(dbCommand);

ds.Tables[0].Rows.Add("Total");

DataGrid2.DataSource = ds;
DataGrid2.DataBind();

example datagrid

最佳答案

可以编写一个“RowDataBound()”事件并单独求和。如下所示。

    public int totalCount = default(int);

    protected void Test_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType.Equals(DataControlRowType.DataRow))
        {
            int count = default(int);
            string text = e.Row.Cells[0].Text;
            int.TryParse(text, out count);
            totalCount = totalCount + count;
        }
    }

希望这有用!!

关于c# - 如何统计我的列的总数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7262393/

相关文章:

c# - 如何在 .NET 中获取此 DateTime 格式

c# - 在 C#/LINQ 中是否有更好/内联的方式来完成以下操作?

c# - 如何从 .Net 中的超线程中获得最大 yield

c# - 在 C# 中手动填充 DataTable 的最快方法

.net - 实现领域驱动设计的功能方式

c# - 如何以编程方式设置 WPF DataGrid 的模板和填充内容?

apache-flex - Flex 3 DataGrid 列宽问题

c# - 通过C#代码创建DataGridTemplateColumn

javascript - 如何在 WinRT C# 应用程序中执行 Javascript 代码?

c# - 将类型 'System.Dynamic.DynamicObject 转换为 System.Collections.IEnumerable