gridview隐藏某一列

gridview隐藏某一列,以前VS2003的用法gridview.columns[index].visible=false;

现在在ASP.NET中此方法隐藏主键列时行不通了

 //分页的grideview隐藏主键列

  protected void gvProductList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //gvProductList.Columns[0].Visible = false;//此方式在ASP.NET隐藏主键列是会出现问题

           //用gridview自带的分页功能进行判断隐藏主键列
            if (e.Row.RowType != DataControlRowType.Pager)
            {
                e.Row.Cells[0].Visible = false;
            }

          //确定是否删除某一行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + ((HyperLink)e.Row.Cells[1].Controls[0]).Text + "\"吗?')");
            }

        }

原文地址:https://www.cnblogs.com/peak/p/1445545.html