DropDownChange

V

vncntj

I'm trying to show and hide web controls based on ListItem value
selected. I thought that if I put the values of the ID's in the
ListItem it would make it easier to acces.

<script runat="server">

protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{

}
</script>

<%@ Register TagPrefix="ED" TagName="Directory" Src="employee.ascx" %>
<%@ Register TagPrefix="GN" TagName="Numbers"
Src="general_numbers.ascx" %>

<asp:Content ID="HeaderContent"
ContentPlaceHolderID="Header_Content" runat="server">

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem value="boo">Employee Directory</
asp:ListItem>
<asp:ListItem value="moo">General Numbers</
asp:ListItem>
</asp:DropDownList>

<ED:Directory ID="boo" runat="server" Visible=true/<GN:Numbers ID="moo" runat="server" Visible=false/
</asp:Content>
 
M

Masudur

I'm trying to show and hide web controls based on ListItem value
selected. I thought that if I put the values of the ID's in the
ListItem it would make it easier to acces.

<script runat="server">

protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{

}
</script>

<%@ Register TagPrefix="ED" TagName="Directory" Src="employee.ascx" %>
<%@ Register TagPrefix="GN" TagName="Numbers"
Src="general_numbers.ascx" %>

<asp:Content ID="HeaderContent"
ContentPlaceHolderID="Header_Content" runat="server">

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem value="boo">Employee Directory</
asp:ListItem>
<asp:ListItem value="moo">General Numbers</
asp:ListItem>
</asp:DropDownList>

<ED:Directory ID="boo" runat="server" Visible=true/

<GN:Numbers ID="moo" runat="server" Visible=false/



</asp:Content>

what is the problem?
 
G

Guest

Howdy,

First, make sure AutoPostBack propertu is set to true:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
<asp:ListItem Value="boo" Text="Employee Directory"/>
<asp:ListItem Value="moo" Text="General Numbers"/>
</asp:DropDownList>

then amend the code:
<script runat="server">

protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
DropDownList dropDownList = (DropDownList) sender;

string value = dropDownList.SelectedValue;

boo.Visible = (value == "boo");
moo.Visible = (value == "moo");
}
</script>

Is that what you want?
 

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

Top