Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
All-Star
97923 Points
14516 Posts
Apr 06, 2012 12:17 PM|LINK
Willem, I remember you, so here goes the code...run it and check it it helps you, or else will write one more code sample for you -
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Selection_Change(object sender, EventArgs e) { int num = Convert.ToInt32(kinderen.SelectedItem.Value); foreach (Control t in Panel1.Controls) { if(t.GetType() == typeof(TextBox)) ((TextBox)t).Style.Add("Visibility", "Visible"); } for (int i = 1; i <= num; i++) { TextBox tb = Panel1.FindControl("TextBox" + i.ToString()) as TextBox; tb.Style.Add("Visibility","Hidden"); } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Panel ID="Panel1" runat="server"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox> </asp:Panel> <asp:DropDownList ID="kinderen" AutoPostBack="True" OnSelectedIndexChanged="Selection_Change" runat="server" Height="26px"> <asp:ListItem Selected="True" Value="1">1</asp:ListItem> <asp:ListItem Value="2">2</asp:ListItem> <asp:ListItem Value="3">3</asp:ListItem> <asp:ListItem Value="4">4</asp:ListItem> <asp:ListItem Value="5">5</asp:ListItem> <asp:ListItem Value="6">6</asp:ListItem> </asp:DropDownList> </div> </form> </body> </html>
ramiramilu
All-Star
97923 Points
14516 Posts
Re: fields visible on basis of the input from the dropdownlist
Apr 06, 2012 12:17 PM|LINK
Willem, I remember you, so here goes the code...run it and check it it helps you, or else will write one more code sample for you -
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Selection_Change(object sender, EventArgs e) { int num = Convert.ToInt32(kinderen.SelectedItem.Value); foreach (Control t in Panel1.Controls) { if(t.GetType() == typeof(TextBox)) ((TextBox)t).Style.Add("Visibility", "Visible"); } for (int i = 1; i <= num; i++) { TextBox tb = Panel1.FindControl("TextBox" + i.ToString()) as TextBox; tb.Style.Add("Visibility","Hidden"); } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Panel ID="Panel1" runat="server"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox> </asp:Panel> <asp:DropDownList ID="kinderen" AutoPostBack="True" OnSelectedIndexChanged="Selection_Change" runat="server" Height="26px"> <asp:ListItem Selected="True" Value="1">1</asp:ListItem> <asp:ListItem Value="2">2</asp:ListItem> <asp:ListItem Value="3">3</asp:ListItem> <asp:ListItem Value="4">4</asp:ListItem> <asp:ListItem Value="5">5</asp:ListItem> <asp:ListItem Value="6">6</asp:ListItem> </asp:DropDownList> </div> </form> </body> </html>JumpStart