日期:2014-05-17  浏览次数:20436 次

GridView后台动态隐藏某列
C# code

if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (Request.QueryString["logLabeled"] == "1")
                {
                    e.Row.Cells[4].Visible = false;
                    e.Row.Cells[5].Visible = true;
                }
                else
                {
                    e.Row.Cells[4].Visible = true;
                    e.Row.Cells[5].Visible = false;
                }
            }



列是隐藏掉了 但是GridView的隐藏列的Header没隐藏掉

------解决方案--------------------
1、protected void GridView_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Visible = false;
}


2、GridView.HeaderRow.Cells[0].Visible = false;
 GridView.FooterRow.Cells[0].Visible = false;
GridView.Rows[i].Cells[0].Visible = false;
------解决方案--------------------
protected void gvFundDetails_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[2].Visible = false;
}
}