Gridview添加合计行问题! 本帖最后由 xjcsghliu 于 2011-10-26 11:13:14 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 直接在DataTable中加合计行,然后绑定到GridView 查询的时候就把合计查出来,或者在datatable里加一行合计 你的这个else if (e.Row.RowType == DataControlRowType.Footer){ e.Row.Cells[3].Text = "合计:"; e.Row.Cells[4].Text = sum.ToString(); e.Row.Cells[5].Text = sum1.ToString();}判断在if (e.Row.RowType == DataControlRowType.DataRow){ //上面的Footer添加的内容你放在了DataRow里,当然执行不到了。}你的那个RowDataBound的if...else 感觉太乱了,自己检查一下先。 以前帮别人写过类似的,你参考一下,原帖地址:http://topic.csdn.net/u/20110820/00/238cba9a-eb6a-495d-a01d-e1d64b98f738.html protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if ((e.Row.Cells[1].Text).Length > 16) { e.Row.Cells[1].Text = (e.Row.Cells[1].Text).Substring(0, 16) + "…"; } if ((e.Row.Cells[2].Text).Length > 16) { e.Row.Cells[2].Text = (e.Row.Cells[2].Text).Substring(0, 16) + "…"; } string id = e.Row.Cells[11].Text.ToString(); stockClass sc = new stockClass(); float not4 = sc.not(id); if (not4 == 0) { e.Row.Cells[11].Text = "<font color=red>0</font>"; } else { e.Row.Cells[11].Text = String.Format("{0:0.00}", not4); } string id2 = e.Row.Cells[10].Text.ToString(); stockClass sc2 = new stockClass(); float not5 = sc.not1(id); if (not5 == 0) { e.Row.Cells[10].Text = "<font color=red>0</font>"; } else { e.Row.Cells[10].Text = String.Format("{0:0.00}", not5); } } else { if (e.Row.RowIndex >= 0) { sum += Convert.ToDouble(e.Row.Cells[4].Text); sum1 += Convert.ToDouble(e.Row.Cells[5].Text); } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = "合计:"; e.Row.Cells[4].Text = sum.ToString(); e.Row.Cells[5].Text = sum1.ToString(); } } } Visa救命! OWC画折线图 如何去掉第一段折线?如下图所示的效果 对象赋值给变量 关于ToolStripSplitButton的问题,请教! 一个oracle里关于循环加变量的问题· 求一个正则表达式 谢谢 请问谁有开放源代码的用户权限管理程序,有相关资料也可以? C#主窗体(Form)键盘响应问题(简单送分啦) C#中有分大小写的么? 用c#做出来的程序在没有装vs.net的机器上无法运行? sql 文的一些问题! 求自定义GridView
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[3].Text = "合计:";
e.Row.Cells[4].Text = sum.ToString();
e.Row.Cells[5].Text = sum1.ToString();
}
判断在
if (e.Row.RowType == DataControlRowType.DataRow)
{
//上面的Footer添加的内容你放在了DataRow里,当然执行不到了。
}你的那个RowDataBound的if...else 感觉太乱了,自己检查一下先。
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.Cells[1].Text).Length > 16)
{
e.Row.Cells[1].Text = (e.Row.Cells[1].Text).Substring(0, 16) + "…";
} if ((e.Row.Cells[2].Text).Length > 16)
{
e.Row.Cells[2].Text = (e.Row.Cells[2].Text).Substring(0, 16) + "…";
}
string id = e.Row.Cells[11].Text.ToString();
stockClass sc = new stockClass();
float not4 = sc.not(id);
if (not4 == 0)
{
e.Row.Cells[11].Text = "<font color=red>0</font>";
}
else
{
e.Row.Cells[11].Text = String.Format("{0:0.00}", not4);
} string id2 = e.Row.Cells[10].Text.ToString();
stockClass sc2 = new stockClass();
float not5 = sc.not1(id);
if (not5 == 0)
{
e.Row.Cells[10].Text = "<font color=red>0</font>";
}
else
{
e.Row.Cells[10].Text = String.Format("{0:0.00}", not5);
}
}
else
{
if (e.Row.RowIndex >= 0)
{
sum += Convert.ToDouble(e.Row.Cells[4].Text);
sum1 += Convert.ToDouble(e.Row.Cells[5].Text);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[3].Text = "合计:";
e.Row.Cells[4].Text = sum.ToString();
e.Row.Cells[5].Text = sum1.ToString();
}
}
}