简体   繁体   English

使用c#.net减去gridview的最后两行

[英]Do subtraction of last two rows of gridview using c#.net

I have a gridview on my page I am binding data from table (Mysql database) to it. 我的页面上有一个gridview,我正在将表(Mysql数据库)中的数据绑定到它。 Also gridview has AutoGenerateColumns property to 'true'. 此外,gridview的AutoGenerateColumns属性为'true'。 Now the gridview have all the columns autogenerated and I have last 2 rows named 'Total' & 'HeadCount'. 现在,gridview具有自动生成的所有列,而我的最后两行名为“ Total”和“ HeadCount”。 I want to subtract 'HeadCount' from 'Total'. 我想从“总计”中减去“ HeadCount”。 And add new row 'Final Total' to the grid. 并将新行“最终总计”添加到网格中。 How can I do this? 我怎样才能做到这一点? Should I do it database side? 我应该在数据库方面吗? If so How? 如果是这样怎么办? Should I do it application c# code side? 我应该在C#代码端使用它吗? If so How? 如果是这样怎么办? Please help me out if anyone has an answer for this. 如果有人对此有答案,请帮助我。 Thanks..! 谢谢..!

Code: 码:

ds=getAllStudents();
gridStuds.DataSource=ds;
gridStuds.DataBind();

do it as code below 作为下面的代码来做

DataColumn totalColumn = new DataColumn();
totalColumn.ColumnName = "FinalTotal";
totalColumn.DataType = typeof (int);
totalColumn.DefaultValue = 0;
dtSourceTable.Columns.Add(totalColumn);

foreach (DataRow row in dtSourceTable.Rows)
{
    row["FinalTotal"] = Convert.ToInt32
       (row["HeadCount"]) - Convert.ToInt32(row["Total"]);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM