首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

GridView靠山动态隐藏某列

2012-09-28 
GridView后台动态隐藏某列C# codeif (e.Row.RowType DataControlRowType.DataRow){if (Request.QuerySt

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

热点排行