DataRowView rowView = (DataRowView)e.Item.DataItem;
 var lxRow = (DataSetQXlx.T_qxlxRow)rowView.Row;//利用数据集中的读取方法,读出一行
 怎么判断这个行中的一个TextBox控件是否为空?
用通常的
if(lxRow.TextBox1=="")
{
  //
}
出现的错误如下
无法将类型为“System.DBNull”的对象强制转换为类型“System.String”。 
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidCastException: 无法将类型为“System.DBNull”的对象强制转换为类型“System.String”。源错误: 
行 578:            get {
行 579:                try {
行 580:                    return ((string)(this[this.tableT_qxlx.lxmcColumn]));
行 581:                }
行 582:                catch (global::System.InvalidCastException e) {
 源文件: c:\Users\0c0c0f\AppData\Local\Temp\Temporary ASP.NET Files\taijiquanweb\cb291efc\e8a0236\App_Code.lxyh0wcb.2.cs    行: 580 

解决方案 »

  1.   

    无法将类型为“System.DBNull”的对象强制转换为类型“System.String”。 
    你的数据集没有取到数据,无法将空值给string
      

  2.   

    这是我写的代码,请指教
      protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            DataRowView rowView = (DataRowView)e.Item.DataItem;
            var lxRow = (DataSetQXlx.T_qxlxRow)rowView.Row;
            if(lxRow.lxmc=="")
            {
               HtmlTableCell trRow = (HtmlTableCell)e.Item.FindControl("tdRow");
               trRow.Attributes["class"] = "new";
            }
        }
      

  3.   

    为什么我e.Item.DataItem这个没有呢,只能点出e.item,没有dataitem