Asp.net2.0GridView隐藏列visible="false" 后你就无法取得这列的值了, 而用datagrid就没有这个问题, MS这个混蛋老是改变游戏规则, 幸好我聪明, 在百度上搜到了别人的解决方法, 然后加入了自己的方法, 才解决问题:
  protected void GVList_RowDataBound(object sender, GridViewRowEventArgs e) 
  { 
  //隐藏不必要的列 
  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事件中书写如下代码:
  void GridView1_RowCreated(object sender, GridViewRowEventArgs e) 
  { 
  if (e.Row.RowType == DataControlRowType.DataRow || 
  e.Row.RowType == DataControlRowType.Header) 
  { 
  e.Row.Cells[0].Visible = false; //如果想使第1列不可见,则将它的可见性设为false 
  } 
  //可以根据需要设置更多的列 
  } 
  因为在RowCreated事件(隐藏)在绑定时候发生,所以这样就即能将数据绑定到列上,又隐藏了该列.所以可以访问到隐藏列的值。
  下面介绍另外一个可以将数据绑定到GridView控件的方法:
Public void myTestFunction() 
  { 
  string conString="....";//省略 
  string sqlquery="...";//省略 
  SqlConnection con = new SqlConnection(conString); 
  SqlDataAdapter da = new SqlDataAdapter(sqlquery, con); 
  DataSet ds = new DataSet(); 
  da.Fill(ds); 
  ds.Tables[0].Columns[0].ColumnMapping = MappingType.Hidden; 
  GridView1.DataSouce = ds.Tables[0]; 
  GridView1.DataBind() ; 
  } 
  文章主要讲述了ASP.NET2.0中GridView控件的隐藏列的问题.
赞
If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
 
 
QQ:154298438
QQ:417480759