Two Level Dynamic DropDown List Error Question
I am trying to dynamicly load selections in a DropDown List based on the section that was selected in the first drop down and display a message when the button is clicked. I get an error message concerning the void on the button click. I will include all of the code for your review.
Thank you,
Brian
Mark up code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TwoLevelDropDown.aspx.cs" Inherits="Demos_TwoLevelDropDown" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedInde xChanged">
<asp:ListItem>Airplaine</asp:ListItem>
<asp:ListItem>Car</asp:ListItem>
<asp:ListItem>Train</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="false">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Font-Bold="True"
onclick="Button1_Click" Text="Selections Button" />
<div>
</div>
</body>
</html>
</form>
C# Code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Demos_TwoLevelDropDown : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string[] CarArray = new string[4] { "Ford", "Honda", "BMW", "Dodge" };
string[] AirplaneArray = new string[3] { "Boeing 777", "Boeing 747", "Boeing 777" };
string[] TrainArray = new string[3] { "Bullet Train", "Amtrack", "Tram" };
if (DropDownList1.SelectedValue == "Car")
{
DropDownList2.DataSource = CarArray;
}
else if(DropDownList1.SelectedValue == "Airplane")
{
DropDownList2.DataSource = AirplaneArray;
}
else
{
DropDownList2.DataSource = TrainArray;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("You selected <b>" +
DropDownList1.SelectedValue.ToStrng() + ": " +
DropDownList2.SelectedValue.ToString() + "</b>");
}
</script>
|