项目遇到,百度下,如下:

protectedvoidGVList_RowDataBound(objectsender,GridViewRowEventArgse)
  {
  //隐藏不必要的列
  if((e.Row.RowType==DataControlRowType.DataRow)||(e.Row.RowType==DataControlRowType.Header)||(e.Row.RowType==DataControlRowType.Footer))
  {
  e.Row.Cells[0].Visible=false;
  e.Row.Cells[3].Visible=false;
  }
  }

在RowCreated事件中书写如下代码:

voidGridView1_RowCreated(objectsender,GridViewRowEventArgse)
  {
  if(e.Row.RowType==DataControlRowType.DataRow||
  e.Row.RowType==DataControlRowType.Header)
  {
  e.Row.Cells[0].Visible=false;//如果想使第1列不可见,则将它的可见性设为false
  }
  //可以根据需要设置更多的列
  }

因为在RowCreated事件(隐藏)在绑定时候发生,所以这样就即能将数据绑定到列上,又隐藏了该列.所以可以访问到隐藏列的值。

posted on 2011-03-31 17:36  Lambert_Zhao  阅读(274)  评论(0编辑  收藏  举报