开发者

CheckBox Control in Visual studio asp.net 2005 C#

开发者 https://www.devze.com 2023-02-11 16:31 出处:网络
May you please help me on this: I developed a web application that has Checkboxes and i want to show some controls when the user tick the box and hide them when the user untick the box. I only managed

May you please help me on this: I developed a web application that has Checkboxes and i want to show some controls when the user tick the box and hide them when the user untick the box. I only managed to do the showing part when the user tick the box, now i'm failing to hide them when the user untick the box.

Here is the showing part of the my code:

 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;
    }

Please help me with the hiding part.

An开发者_如何学JAVAy help please!!! It will be highly appreciated


You need to set the Visible property to the checkbox's Checked property.


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

EDIT: More elegant solution would be to put these controls in a Panel and just set the Visible property of that using the checkbox's Checked property


As SLaks says

just set

<Yourontrolname>.Visible = chkboxMentor.checked

for each control you wish to toggle


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; 
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消