日期:2014-05-18  浏览次数:20417 次

ListBox 动态绑定去空值
ListBox 动态绑定有些数据部分是空值
显示到ListBox上都是空

什么代码可以在显示的时候去除空值啊?谢谢大家
 protected void BindListBoxG()//绑定相近工种
  {
  cmd.Connection = conn;
  conn.Open();

  sql2 = "select gzmc,id from LbGzxxb order by id asc";

  cmd.CommandText = sql2;
  SqlDataReader reader = cmd.ExecuteReader();
  LstGjd.DataSource = reader;
  LstGjd.DataTextField = "gzmc";
  LstGjd.DataValueField = "id";
  LstGjd.DataBind();
  reader.Close();
  conn.Close();
  }

------解决方案--------------------
sql2 = "select gzmc,id from LbGzxxb where gzmc<>'' order by id asc";


------解决方案--------------------
id不为空吧?
如果gzmc可能为空的话,过滤一下就好了
sql2 = "select gzmc,id from LbGzxxb where gzmc<>'' or gzmc<>null order by id asc";
------解决方案--------------------
+++,在取数据的时候把空的去掉
探讨

sql2 = "select gzmc,id from LbGzxxb where gzmc<>'' order by id asc";