Visual Studio asp.net 2005中的CheckBox控件C#

时间:2011-02-18 12:53:39

标签: c# asp.net

请你帮我解决这个问题:我开发了一个带有Checkboxes的Web应用程序,我希望在用户勾选框时显示一些控件,并在用户取消框时隐藏它们。当用户勾选方框时,我只设法显示部分,现在当用户取消选中框时我没有隐藏它们。

以下是我的代码的显示部分:

 protected void chkboxMentor_CheckedChanged(object sender, EventArgs e)
    {
        lblMentorName.Visible = true;
        txtMentorName.Visible = true;
        lblMentorStuff.Visible = true;
        txtMentorStaffNo.Visible = true;
        lblMentorDate.Visible = true;
        btnShowCal.Visible = true;
    }

请帮我隐藏部分。

任何帮助请!!!非常感谢

4 个答案:

答案 0 :(得分:1)

您需要将Visible属性设置为复选框的Checked属性。

答案 1 :(得分:1)

        lblMentorName.Visible = chkBoxMentor.Checked;
        txtMentorName.Visible = chkBoxMentor.Checked;
        lblMentorStuff.Visible = chkBoxMentor.Checked;
        txtMentorStaffNo.Visible = chkBoxMentor.Checked;
        lblMentorDate.Visible = chkBoxMentor.Checked;
        btnShowCal.Visible = chkBoxMentor.Checked;

编辑:更优雅的解决方案是将这些控件放在Panel中,并使用复选框的Visible属性设置Checked属性

答案 2 :(得分:0)

正如SLaks所说

只需设置

<Yourontrolname>.Visible = chkboxMentor.checked

对于您要切换的每个控件

答案 3 :(得分:0)

protected void chkboxMentor_CheckedChanged(object sender, EventArgs e) 
{ 
     if(chkboxMentor.Checked)
    {
        lblMentorName.Visible = true;
        txtMentorName.Visible = true; 
        lblMentorStuff.Visible = true;
        txtMentorStaffNo.Visible = true;
        lblMentorDate.Visible = true;
        btnShowCal.Visible = true; 
    }
    else
    {

        lblMentorName.Visible = false;
        txtMentorName.Visible = false; 
        lblMentorStuff.Visible = false;
        txtMentorStaffNo.Visible = false;
        lblMentorDate.Visible = false;
        btnShowCal.Visible = false; 
    }
}