Click here to Skip to main content
15,905,612 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a Checkboxlist,button and 2 textboxes

When selecting the first value in the checkboxes and press button i want to display it in one of the textboxes and when i uncheck the checkboxes i want the value to disepear from the textboxes
C#
if (CheckBoxPersonalInfo.SelectedIndex==0)
                {
                    LabelFirstName.Text = theEmpl.firstname;
                    

                    Label1.Text = CheckBoxPersonalInfo.SelectedItem.Value;
                   

                }
                else if (CheckBoxPersonalInfo.SelectedIndex != -1)
                {
                    LabelFirstName.Text = string.Empty;
                }
                if(CheckBoxPersonalInfo.SelectedIndex==1)
                {
                    LabelLastName.Text = theEmpl.lastname;
                }
                else if (CheckBoxPersonalInfo.SelectedIndex != -1)
                {
                    
                }
                {
                    LabelLastName.Text = string.Empty;

                }
Posted

This may be helpfull to you,
you can get values of check box in following way,

C#
bool didYouCheckTheBox = myCheckbox.IsChecked;  // returns true or false


Now remaining is that,
Just handle it working on button click.
So full code you required may be like,
C#
buttonClickFunction()
{
     bool didYouCheckTheBox = myCheckbox.IsChecked;  // returns true or false
     if(didYouCheckTheBox)
     {
         TextBox1.Text = "Checked";
         TextBox2.Text = "";
     }
     else
     {
        TextBox1.Text = "";
        TextBox2.Text = ""Un Checked";
     }
}
 
Share this answer
 
Comments
Kurac1 16-Apr-13 9:04am    
@Code Block i am using asp and c# so i dont have .Ischecked
Coder Block 16-Apr-13 9:12am    
Better mentioned it while asking question,
But are you using asp class??
Coder Block 16-Apr-13 9:15am    
and yes whatever u use,
Logic are same whole syntax will change.
C#
private void checkBox_CheckedChanged(object sender, EventArgs e)
{
    var checkboxes = from c in groupBox1.Controls.OfType<CheckBox>()
                        where c.Checked
                        orderby int.Parse(c.Name.Substring(8))
                        select c;

    sb.Clear();

    foreach (var cb in  checkboxes)
    {
        sb.Append(string.Format("This is checkbox {0}", cb.Name.Substring(8)));
        sb.Append(Environment.NewLine);
    }

    textBox1.Text = sb.ToString();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900