Hi.I have 4 textboxes, nr. 1 is set to visible by default and the other 3 are set to not visible by default. I want my program to work like this, if I choose 2 in my dropdown list, I want 2 textboxes to be visible. If I choose 3 from the dropdown list, I want 3 textboxes to be visible and so on... This is my code ( just using Default.aspx and Default.aspx.cs - will change the names when it works );Default.aspx
<tr> <td> </td> <td style="width: 3px"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox3" runat="server" Visible="False"></asp:TextBox> <asp:TextBox ID="TextBox4" runat="server" Visible="False"></asp:TextBox></td> <td style="width: 3px"> <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem Selected="True">1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> <asp:ListItem>5</asp:ListItem> <asp:ListItem>6</asp:ListItem> </asp:DropDownList></td> </tr>
Default.aspx.cs ( tried a couple of different things here, nothing works )
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { if (DropDownList1.SelectedIndex.Equals(2)) { TextBox2.Visible = true; } else if (DropDownList1.SelectedValue.Equals("3")) { TextBox2.Visible = true; TextBox3.Visible = true; } else if (DropDownList1.SelectedItem.Equals("4")) { TextBox2.Visible = true; TextBox3.Visible = true; TextBox4.Visible = true; } }
Nothing happens when I choose something from the dropdownlist. Please help me. Are there any better ways to this, then please do inform me.Best regards.