繁体   English   中英

在GridView中检查空值

[英]check null value in the gridview

我在gridview中有2列,我想检查该列是否为null,然后该列将被隐藏..我使用了很多方法,但无法获得正确的结果

这是我的代码

     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.Cells[8].Text == "")
    {
        e.Row.Cells[8].Visible = false;
        e.Row.Cells[9].Visible = false;
    }
}

我也尝试过检查是否等于空字,但存在相同的问题列未隐藏

尝试这样的事情:

if (e.Row.RowType == DataControlRowType.DataRow)
{
  string val = Convert.ToString(e.Row.Cells[0]);  //check first cell value
  if(string.IsNullorEmpty(val) )             
  {
     gv.Columns[0].Visible = false;     //Hides First Column
  }
}

尝试这个:

if(!Convert.IsDBNull(GridView1.Rows[0].Cells[8].Value))
{
    GridView1.Rows[0].Cells[8].Visible = false;
}       

尝试更改查询,例如:

select id,name,ISNULL(rate,0) from example
else  use IsNull(rate,'')

您必须像这样更改并将查询放入Bind()函数中

不确定可以尝试这种方式:

if (e.Row.RowType == DataControlRowType.DataRow)
         {
             // This line will get the reference to the underlying row
             DataRowView _row = (DataRowView)e.Row.DataItem;
             if (_row = null)
             {
               GridView1.Columns[0].Visible = false;
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM