首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎么判定dbnull?

2012-03-17 
如何判定dbnull???我在一个Gridv显示用,绑定的数据中存在dbnull值!!我编的程序是:protected void grvView_

如何判定dbnull???
我在一个Gridv显示用,绑定的数据中存在dbnull值!!
我编的程序是:
protected void grvView_RowDataBound(object sender, GridViewRowEventArgs e)
  {
  if (e.Row.RowIndex >= 0)
  {
  if (!(e.Row.Cells[6].Text.ToString() == DBNull.Value.ToString()))
  {
  {
  string str = e.Row.Cells[6].Text.ToString();
  if (str != null && str.Length != 0)
  {
  int num = Convert.ToInt32(str);
  if(num>0)
  e.Row.Cells[6].ForeColor = System.Drawing.Color.Red;
  }
  }
  }
  }
  }
其中cell[6]就是存在dbnull的列....我用断点测试过,当运行到含有dbnull的行时,str就会变成“&nbsp”,但它却进了if (str != null && str.Length != 0)条件中导致出错....谁能帮我解决下啊??拜托

[解决办法]
先str = str.Trim() 一下。 再 if(str != null && !str.Equals(DBNull.Value))
[解决办法]
string str = e.Row.Cells[6].Text.ToString(); 
改成
string str = e.Row.Cells[6].Text;

热点排行