<%@ Page EnableSessionState="false" %>
<html>
<head>
<title>C# Primer: Conditional Switch Statement</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void Page_Load ( Object Sender, EventArgs e ) {
if ( !IsPostBack ) {
// initialize selection
myList.SelectedIndex=3;
book.KeywordFilter="csharp";
showBook ( );
}
else {
// get selection
// each case label in a switch statement can call a different method.
// this example simply shows the gist.
switch ( myList.SelectedIndex ) {
case 1:
book.KeywordFilter="aspnet";
showBook ( );
break;
case 2:
book.KeywordFilter="adonet";
showBook ( );
break;
case 3:
book.KeywordFilter="csharp";
showBook ( );
break;
case 4:
book.KeywordFilter="vbnet";
showBook ( );
break;
case 5:
book.KeywordFilter="xml";
showBook ( );
break;
}
}
}
void showBook ( ) {
string filter = myList.SelectedItem.Text;
filter = filter == "C#" ? "C sharp" : filter;
msg.Text="<a href='http://www.amazon.com/exec/obidos/external-search?tag=rvnunz0525-20&mode=books&keyword=" +
filter + "' target='_blank'>Check out other " + myList.SelectedItem.Text + " books at Amazon</a>";
book.Visible = true;
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>C# Primer: <span class="hilite">Conditional Switch Statement</span></h2></div>
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<p>Select subject:
<asp:dropdownlist id="myList" width=100 runat="server">
<asp:listitem />
<asp:listitem text="ASP.NET"/>
<asp:listitem text="ADO.NET"/>
<asp:listitem text="C#"/>
<asp:listitem text="VB .NET"/>
<asp:listitem text="XML.NET"/>
</asp:dropdownlist>
<asp:button text="Submit" runat="server" />
<p><asp:adrotator id="book" visible=false
advertisementfile="~/shared/books.xml"
bordercolor="silver" borderwidth=1
target="_blank" height=140 runat="server" />
<p><asp:label id="msg" runat="server" />
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>