1.实现隐藏
添加一个CheckBox1 显示隐藏家庭住址
public void bind()
...{
string sqlstr = "select top 5 * from Employee";
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds, "Employee");
GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[] ...{ "身份证号码" };
GridView1.DataBind();
sqlcon.Close();
GridView1.Columns[3].Visible = false;//一开始隐藏
CheckBox1.Checked = false;//如果不这样后面的代码会把他True
}
2.双击CheckBox1,在CheckedChanged方法里写上代码,最后代码如下:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
...{
GridView1.Columns[3].Visible=! GridView1.Columns[3].Visible;
}
注意:CheckBox1的AutoPostBack要True!