How to show textboxes depending on checkbox list selected

Steps:

1. Add one checklist from toolbox in form. Make id as ‘CheckBoxList1’.
2. Add three textbox from toolbox in form. Make id as textbox1, textbox2 and textbox3 respectively.
3. Make checklist ‘autopostback’ property true.
4. Make textboxes visible property ‘false’.
5. Now add the following code in CheckBoxList1_SelectedIndexChanged event.

protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem li in CheckBoxList1.Items)
{
if ((li.Value =="0") && (li.Selected ==true))
{
TextBox1.Visible = true;
TextBox2.Visible = false;
TextBox3.Visible = false;
}
if ((li.Value == "1") && (li.Selected == true))
{
TextBox1.Visible = false;
TextBox2.Visible = true;
TextBox3.Visible = false;
}
if ((li.Value == "2") && (li.Selected == true))
{
TextBox1.Visible = false;
TextBox2.Visible = false;
TextBox3.Visible = true;
}
}
}
How to show textboxes depending on checkbox list selected How to show textboxes depending on checkbox list selected Reviewed by kamal kumar das on October 25, 2011 Rating: 5

No comments:

ads 728x90 B
Powered by Blogger.