Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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
 
Old October 1st, 2007, 08:59 AM
Authorized User
 
Join Date: Sep 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default A constant value is expected

Hi everyone,
I am trying to display some info in a drop down list. I am taking this info from an array. The problem is when I want to read each drop down list's value, I have to assign it programatically so I chose to use switch function like this:

protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string category = ((DropDownList)CreateUserWizard1.CreateUserStep.Co ntentTemplateContainer.FindControl("ddl2")).Select edItem.Value.ToString();

        switch (category)
        {
            case category = "January":
                Response.Write(category);
                break;
        }

    }
and get this error: A constant value is expected. Please help:(
 
Old October 1st, 2007, 09:05 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Look up the syntax for the switch statement, you need:
Code:
switch (category) 
        {
            case "January":
                Response.Write(category);
                break;
        }


--

Joe (Microsoft MVP - XML)
 
Old October 1st, 2007, 09:08 AM
Authorized User
 
Join Date: Sep 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you joefawcett you've been a lot of help to me:)





Similar Threads
Thread Thread Starter Forum Replies Last Post
constant reference in C#? texasraven C# 19 December 13th, 2007 08:28 AM
C# constant functions viveksrivastava C# 4 December 6th, 2007 10:44 PM
Constant pointer and pointer to a constant [email protected] C++ Programming 2 June 5th, 2007 01:39 AM
Constant in VBScript savoym VBScript 2 May 18th, 2005 06:53 AM
Static vs constant stoneman Access 2 December 10th, 2003 09:12 PM





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