Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 2nd, 2008, 08:24 PM
Authorized User
 
Join Date: Apr 2008
Location: Rockville, MD, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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>
  #2 (permalink)  
Old May 3rd, 2008, 02:37 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Is this related to the book Beginning ASP.NET 3.5? If so, can you specify which chapter / page this is about?

If it's not related, can you please post this question in the general Beginning ASP.NET forum: http://p2p.wrox.com/forum.asp?FORUM_ID=348

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page Submission - DropDown List-Error venkikrao PHP How-To 1 August 13th, 2008 10:46 AM
Two Level Dynamic DropDown Question workib ASP.NET 3.5 Basics 6 May 14th, 2008 09:18 PM
Dropdown list question dcct84 C# 4 October 2nd, 2007 02:48 PM
Datagrid error with inline dropdown list hardysmith Classic ASP Basics 0 March 11th, 2005 09:36 AM
Dropdown list question NeoDelphi C# 3 December 25th, 2004 12:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.