Question abt WebForm.

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
 
?

=?ISO-8859-1?Q?Anders_Nor=E5s?=

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top