在Gridview 的 RowCreated事件中书写如下代码:
void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
  
if (e.Row.RowType == DataControlRowType.DataRow || 
      e.Row.RowType 
== DataControlRowType.Header)
  {
    
//隐藏第1列
    e.Row.Cells[0].Visible = false;
    
//可以根据需要隐藏更多的列
  }        
}
因为在RowCreated事件(隐藏)在绑定时候发生,所以这样就即能将数据绑定到列上,又隐藏该列,所以可以访问到隐藏列的值。
protected void gvUnit_RowDataBound(object sender, GridViewRowEventArgs e)
{
  
if (e.Row.RowType == DataControlRowType.DataRow)
  { 
    
//获取隐藏列的值
    if (e.Row.Cells[1].Text == "xxx")
    {
      
//TODO
    }
  }
}

相关文章:

  • 2022-12-23
  • 2022-01-24
  • 2022-12-23
  • 2021-08-25
  • 2021-12-29
  • 2021-07-07
  • 2021-10-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-10-07
  • 2021-12-17
相关资源
相似解决方案