我在一个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)条件中导致出错....谁能帮我解决下啊??拜托