Asp.net 根据复选框的选择隐藏GridView的行

Asp.net 根据复选框的选择隐藏GridView的行,asp.net,gridview,checkbox,Asp.net,Gridview,Checkbox,如果选中了GridView行第一列中的复选框,我想隐藏该行。 若我选中一些复选框并单击deactivate按钮,那个么选中的行应该被隐藏。 如果我选中一些复选框并单击激活按钮,则应显示选中的行 我的代码是 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Sy

如果选中了GridView行第一列中的复选框,我想隐藏该行。 若我选中一些复选框并单击deactivate按钮,那个么选中的行应该被隐藏。 如果我选中一些复选框并单击激活按钮,则应显示选中的行

我的代码是

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace GalleryAnd_Album
{
    public partial class view_album : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("Data Source=PRAVIN-LENOVO\\SQLEXPRESS;Initial Catalog=Gallery;Integrated Security=True");
            SqlDataAdapter da = new SqlDataAdapter("select * from Album", con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            GridView1.DataSource = dt;
            DataBind();
        }


        protected void btnactive_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in GridView1.Rows)
            {
                var chk = row.FindControl("CheckBox1") as CheckBox;
                if (chk.Checked)
                {
                    GridView1.Rows[1].Visible = false;
                }
            }
        }

    }
}

代码需要使用一个变量来跟踪每一行,因为它当前使用硬编码索引1。 可以使用row.RowIndex属性跟踪特定行,因此代码如下所示:

GridView1.Rows[row.RowIndex].Visible = false;

你面临的问题是什么?代码似乎正常。我想隐藏多行。Bt此代码仅隐藏一个如何检查每行中的复选框是否选中??我怎样才能相应地隐藏那一行??