如何让C#中的绑定字段遇到0值时 显示为空????

kkk444dsfsa 2010-11-09 02:27:32
如何让C#中的绑定字段遇到0值时 显示为空????
不能修改sql语句 因为后面还有合计行 如果在Sql中 将字段设为空的话 不能统计??

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
//e.Row.Cells[8].
//e.Row.Cells[9].Text = "";这个好像是把header设为空 ,我是想把值设为空 //e.Row.Cells[10].Text = "";
//e.Row.Cells[11].Text = "";
//e.Row.Cells[12].Text = "";
//e.Row.Cells[13].Text = "";
//e.Row.Cells[14].Text = "";
//e.Row.Cells[15].Text = "";
//e.Row.Cells[16].Text = "";
//e.Row.Cells[17].Text = "";

}

}
...全文
375 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
kkk444dsfsa 2010-11-09
  • 打赏
  • 举报
回复
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[8].Text = e.Row.Cells[8].Text == ""?"0":e.Row.Cells[8].Text ;
}

}

这也不行 不管放在rowcreated 或者RowDataBound 都不行
阿旭 2010-11-09
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wuhan_dotnet 的回复:]

C# code

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[8].Text = e.Row.Cells[8].Text == ""?"0":e……
[/Quote]

这个不行吗?
yaojie1314 2010-11-09
  • 打赏
  • 举报
回复
上面说了,可以使用三元运算符
kkk444dsfsa 2010-11-09
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 tingting74998 的回复:]
在sql语句中用case when 实现啊。我都是这样的,不影响其他。
[/Quote]

在sql中用case when 是可以的 但是 我后面的不能统计啊
如果hwztj为0时 他显示 空
到统计的时候
private double hwztjhj = 0.00;
if(e.row.RowIndex >=0)
{
hwztjhj += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,"hwztj"));//在这边出错,输入的字符串格式不正确???
}
dangbuzhu 2010-11-09
  • 打赏
  • 举报
回复
使用3目运算符。
wuhan_dotnet 2010-11-09
  • 打赏
  • 举报
回复
一般在RowDataBound事件中写
wuhan_dotnet 2010-11-09
  • 打赏
  • 举报
回复

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[8].Text = e.Row.Cells[8].Text == ""?"0":e.Row.Cells[8].Text ;
}

}


whowhen21 2010-11-09
  • 打赏
  • 举报
回复
你写在RowCreated事件~~?
tingting74998 2010-11-09
  • 打赏
  • 举报
回复
在sql语句中用case when 实现啊。我都是这样的,不影响其他。
kkk444dsfsa 2010-11-09
  • 打赏
  • 举报
回复
是的 还不行
kkk444dsfsa 2010-11-09
  • 打赏
  • 举报
回复
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[8].Text = "";
e.Row.Cells[9].Text = "";
e.Row.Cells[10].Text = "";
e.Row.Cells[11].Text = "";
e.Row.Cells[12].Text = "";
e.Row.Cells[13].Text = "";
e.Row.Cells[14].Text = "";
e.Row.Cells[15].Text = "";
e.Row.Cells[16].Text = "";
e.Row.Cells[17].Text = "";

}

}

也不行啊
阿非 2010-11-09
  • 打赏
  • 举报
回复
|| e.Row.RowType == DataControlRowType.Header 去掉

只用 if (e.Row.RowType == DataControlRowType.DataRow )

110,532

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧