Hello,
I have an issue that has been worrying me for days now. I need help please.
Notice that when user sets back the dropdown to qty and deselects the checkbox, the dropdown still remains enabled.
How can i make to return back to disabled when qty is selected?
C#
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked == true)
{
Product1DropDown.Enabled = true;
}
else
{
Product1DropDown.Enabled = false;
Subtotal1.Text = ("0").ToString();
}
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox2.Checked == true)
{
Product2DropDown.Enabled = true;
}
else
{
Product2DropDown.Enabled = false;
Subtotal2.Text = ("0").ToString();
}
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox3.Checked == true)
{
Product3DropDown.Enabled = true;
}
else
{
Product3DropDown.Enabled = false;
Subtotal3.Text = ("0").ToString();
}
}
protected void Product1DropDown_SelectedIndexChanged(object sender, EventArgs e)
{
if (Product1DropDown.SelectedIndex > -1)
{
Qty1.Text = Product1DropDown.SelectedItem.Text;
Subtotal1.Text = Convert.ToString(Convert.ToInt32(Qty1.Text) * Convert.ToInt32(unitprice1.Text)).ToString();
}
}
protected void Product2DropDown_SelectedIndexChanged(object sender, EventArgs e)
{
if (Product2DropDown.SelectedIndex > -1)
{
Qty2.Text = Product2DropDown.SelectedItem.Text;
Subtotal2.Text = Convert.ToString(Convert.ToInt32(Qty2.Text) * Convert.ToInt32(unitprice2.Text)).ToString();
}
}
<asp:UpdatePanel ID="panel" runat="server">
<ContentTemplate>
<div class="row" id="producthead" style="width: 100%;">
<div class="col-md-5">
<asp:Label ID="Label5" runat="server" Text="Product" Font-Bold="true"></asp:Label>
</div>
<div class="col-md-1">
</div>
<div class="col-md-2">
<asp:Label ID="Label2" runat="server" Text="Unit Price" Font-Bold="true"></asp:Label>
</div>
<div class="col-md-2">
<asp:Label ID="Label6" runat="server" Text="Quantity" Font-Bold="true"></asp:Label>
</div>
<div class="col-md-2">
<asp:Label ID="Label3" runat="server" Text="Sub Total" Font-Bold="true"></asp:Label>
</div>
<hr style="width: 100%; border: 1px solid #DCDCDC;" />
</div>
<table style="width: 100%;">
<tr style="width: 100%;">
<td style="width: 100%;">
<div class="row" style="width: 100%;">
<div class="col-md-5">
<label>Product1</label>
</div>
<div class="col-md-1">
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" />
</div>
<div class="col-md-2">
<asp:Label ID="unitprice1" runat="server" Text="100"></asp:Label>
</div>
<div class="col-md-2">
<asp:DropDownList ID="Product1DropDown" runat="server" CssClass="form-control" AutoPostBack="true" Width="80" Enabled="false" OnSelectedIndexChanged="Product1DropDown_SelectedIndexChanged">
<asp:ListItem Selected="True" Text="Qty"></asp:ListItem>
<asp:ListItem Value="1"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
<asp:ListItem Value="3"></asp:ListItem>
<asp:ListItem Value="4"></asp:ListItem>
</asp:DropDownList>
</div>
<div class="col-md-2">
<asp:Label ID="Qty1" runat="server" Visible="false" Text=""></asp:Label>
<asp:Label ID="Subtotal1" runat="server" Text=""></asp:Label>
</div>
</div>
</td>
</tr>
<tr>
<td>
<hr style="width: 100%; border: 1px solid #DCDCDC;" />
</td>
</tr>
<tr style="width: 100%;">
<td style="width: 100%;">
<div class="row" style="width: 100%;">
<div class="col-md-5">
<label>Product2</label>
</div>
<div class="col-md-1">
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox2_CheckedChanged" />
</div>
<div class="col-md-2">
<asp:Label ID="unitprice2" runat="server" Text="200"></asp:Label>
</div>
<div class="col-md-2">
<asp:DropDownList ID="Product2DropDown" runat="server" CssClass="form-control" AutoPostBack="true" Width="80" Enabled="false" OnSelectedIndexChanged="Product2DropDown_SelectedIndexChanged">
<asp:ListItem Selected="True" Text="Qty"></asp:ListItem>
<asp:ListItem Value="1"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
<asp:ListItem Value="3"></asp:ListItem>
<asp:ListItem Value="4"></asp:ListItem>
</asp:DropDownList>
</div>
<div class="col-md-2">
<asp:Label ID="Qty2" runat="server" Visible="false" Text=""></asp:Label>
<asp:Label ID="Subtotal2" runat="server" Text=""></asp:Label>
</div>
</div>
</td>
</tr>
<tr>
<td>
<hr style="width: 100%; border: 1px solid #DCDCDC;" />
</td>
</tr>