In this example we’re going to create a user control with an enumerated property that you will be able to choose via Intellisense.
I’m going to begin by creating my user control NewsHeadline.ascx:
Then in my code behind I’ll create an enumeration that contains all of the news categories I’ll be dealing with:
{
}
publicenumNewsCategory
{
BreakingNews=0,
Business=1,
Sports=2,
Money=3,
Local=4
}
publicpartialclassNewsHeadline : System.Web.UI.UserControl
{
publicNewsCategory _category { get; set; }
[Browsable(true)] // Needed to display in Intellisense popup
publicNewsCategory View
{
get
{
return _category;
}
set
{
_category = value;
DisplayNewsByEnum(_category);
}
}
}
I choose to use a switch statement since Visual Studio will auto-generate your cases once you enclose the enumeration in the parenthesis.
{
switch (View)
{
caseNewsCategory.BreakingNews:
Label1.Text = “Breaking News”;
break;
caseNewsCategory.Business:
Label1.Text = “Business”;
break;
caseNewsCategory.Sports:
Label1.Text = “Sports”;
break;
caseNewsCategory.Money:
Label1.Text = “Money”;
break;
caseNewsCategory.Local:
Label1.Text = “Local”;
break;
default:
Label1.Text = “No selection made”;
break;
}
}
That’s all you need, you may need to build the site once before the enumeration shows up but be patient and it should recognize it no problem.
As well as in design mode