aic007 Posted April 14, 2007 Share Posted April 14, 2007 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. Link to comment Share on other sites More sharing options...
shah_ankitb Posted April 14, 2007 Share Posted April 14, 2007 I don't know anything about ASP but i am trying to help u because u din't get any answer.First Of All Check that On Change Event Of DropDown Box Function Is Called Or Not. Try to Supply Right Arguments.In the Written Function Check For the Value Ur Getting Or Not Which U Select.First Of All Does Not Define Any Text To <Visible="False">After the Selection Of Value U Can Do that In 'Default.aspx.cs'. In this File As per Selection Give Permissions of Visible 'False' or 'True'. Say For ExampleIf U Select From DropDown '2'TextBox1.Visible = true;TextBox2.Visible = true;TextBox3.Visible = true;TextBox4.Visible = true;Do as above. Might This Will Help U. Just Give U Hint to Sorted Out U'r Problem. Link to comment Share on other sites More sharing options...
aic007 Posted April 15, 2007 Author Share Posted April 15, 2007 Thanx alot for trying to help Link to comment Share on other sites More sharing options...
justsomeguy Posted April 16, 2007 Share Posted April 16, 2007 Are you expecting the page to change immediately when the value is selected, or should the page change when they hit the submit button? The way it is set up now, the page will change when the submit button is pressed. ASP.NET writes a lot of your code for you to make stuff like that happen, but that also makes it a little difficult to add your own Javascript event handlers to handle client-side events, which is what it sounds like you want this to do. Link to comment Share on other sites More sharing options...
jesh Posted April 17, 2007 Share Posted April 17, 2007 Like justsomeguy said, nothing is going to happen on your page until it posts back to the server. You can automate this (so that the user doesn't have to click a submit button) by modifying your DropDownList like so: <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true"> Otherwise, you'll have to use javascript to make those fields appear and disappear. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now