请教各位大侠,我想通过一个Button点击事件来隐藏GridView中的某一列,这样可以实现吗?注:Button不是嵌在GridView中,而是独立在外的一般Button。

解决方案 »

  1.   

    找到那个列,设置其visible属性
      

  2.   

    Button_OnClick:遍历 GridView.Rows,设置 GridView.Rows[i].Cells[j].Visible=false;
      

  3.   

    也可以采用js进行处理。
    tabel1.rows[i].cells[j].style.display="none"
      

  4.   

    Button 点击事件GridView1.Cells[第几列].Visable=false;
      
      

  5.   

    string SqlDelStr = "delete from useradmin where userid=" + this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();SelectedRows表示的是在DataGridView中所选择的行,其中Count属性是表示的选择的行数
    CurrentRow表示的就是所选择的当前行,只有一行
    dataGridView1.Rows[dataGridView1.CurrentRow.Index ].Cells["id"].Value.ToString() ;
      

  6.   


    还是不行,下面是我的代码,新手,求救protected void Button1_Click(object sender, EventArgs e)
            {
                gvView.Cells[5].Visable = false;
                BindData();
            }错误 22 “System.Web.UI.WebControls.GridView”不包含“Cells”的定义,并且找不到可接受类型为“System.Web.UI.WebControls.GridView”的第一个参数的扩展方法“Cells”(是否缺少 using 指令或程序集引用?)
      

  7.   

    this.GridView1.Columns[0].Visible = false;
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
                for (int i = 1; i <= 7; i++)
                {
                    this.GridView1.Rows[i].Columns["列名"].Visible = false; 
                }
         }