GridView的隐藏行不能取值 visible=false

时间:2021-10-04 17:08:38

 

 GridView 隐藏列 visible="false" 后 你就无法取得这列的值了, 而用datagrid就没有这个问题;原因是你绑定数据前就设置了该列隐藏,
MS就为了提高效率,不再加载该列的数据;解决办法就是,在加载后,设置为隐藏;如下
 easy, too easy -----
--------------------------------------------------
 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;                
            }

}

--------------------------------------------------