SERVER SIDE SCRIPT
I wrote this code to make a web form that ADDS or REMOVES items in the Listbox when the checkbox is checked or unchecked but even after checking and unchecking the checkboxes nothing is happening.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 250px;
}
</style>
</head>
<body style = "background-color:darksalmon; font-style:oblique; font-family:'Gill Sans MT'">
<form id="form1" runat="server">
<div>
<center>
<table border="3" border-color="black">
<tr>
<td colspan="2" border="2" align="center">
<asp:ListBox ID="ListBox1" runat="server" Height="414px" Width="316px"></asp:ListBox>
</td>
<td class="auto-style1">
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" Text="PHP" />
<br />
<br />
<asp:CheckBox ID="CheckBox2" runat="server" OnCheckedChanged="CheckBox2_CheckedChanged" Text="JAVA" />
<br />
<br />
<asp:CheckBox ID="CheckBox3" runat="server" OnCheckedChanged="CheckBox3_CheckedChanged" Text="C" />
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if(CheckBox1.Checked == true)
{
ListBox1.Items.Add(CheckBox1.Text);
}
else
{
ListBox1.Items.Remove(CheckBox1.Text);
}
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox2.Checked == true)
{
ListBox1.Items.Add(CheckBox2.Text);
}
else
{
ListBox1.Items.Remove(CheckBox2.Text);
}
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox3.Checked == true)
{
ListBox1.Items.Add(CheckBox3.Text);
}
else
{
ListBox1.Items.Remove(CheckBox3.Text);
}
}
I tried to change the coding at "protected-void CheckBox1_CheckedChanged(object sender, EventArgs e)"
but nothing is being added to the list even after checking the checkbox.!!