Question abt WebForm.

  • Thread starter Thread starter Wong CS
  • Start date Start date
W

Wong CS

Dear all,

i hav a question.. i hav a dropdown list, with Apple, Banana, and Other
value in it.

What i wanna do is, when Other is selected, then 1 lable and 1 textbox
occured to let user to key in the Other value....

how can i achieve it..??

thanks and pls advice.



cheers,
CS
 
Wong said:
i hav a question.. i hav a dropdown list, with Apple, Banana, and Other
value in it.

What i wanna do is, when Other is selected, then 1 lable and 1 textbox
occured to let user to key in the Other value....
You can show and hide the Label and TextBox controls based on the
selection in the DropDownList. The following example (C#) show how this
can be done:
<%@ Page language="c#" AutoEventWireup="true" %>
<script runat="server">
void Page_Load()
{
}
void SelectedIndexChanged(object src, EventArgs e) {
if (((DropDownList)src).SelectedItem.Value=="Other") {
Label1.Visible=true;
TextBox1.Visible=true;
} else {
Label1.Visible=false;
TextBox1.Visible=false;
}
}
</script>
<html>
<body>
<form runat="server">
<asp:DropDownList AutoPostBack="true"
OnSelectedIndexChanged="SelectedIndexChanged" ID="DropDownList1"
Runat="server">
<asp:ListItem Value="Banana">Banana</asp:ListItem>
<asp:ListItem Value="Apple">Apple</asp:ListItem>
<asp:ListItem Value="Other">Other</asp:ListItem>
</asp:DropDownList>
<asp:Label Visible="false" ID="Label1" Runat="server" Text="Name
of fruit:"></asp:Label>
<asp:TextBox Visible="false" ID="TextBox1"
Runat="server"></asp:TextBox>
</form>
</body>
</html>

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Back
Top