读书人

GridView靠山动态隐藏某列

发布时间: 2012-09-28 00:03:35 作者: rapoo

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;
}
}

读书人网 >asp.net

热点推荐