Bilal Haidar Blog
Oct 24 2008
Scott Michelle has an amazing series on building Dynamic Data-Driven User Interfaces with ASP.NET. You can check the series here:
Enjoy the series!
Tags: ASP.NET 2.0
Jul 24 2008
Now you can check my book on www.amazon.com by visiting the following link:
Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB
Isn't this cool? I am extremely happy!!
Tags: ASP.NET 2.0, ASP.NET 3.5, ASP.NET Security
Jul 22 2008
Here is a snippet code that helps you bind the items contained in an enumeration into a DropDownList in ASP.NET.
To start with, let us define an enumeration as follows:
public enum Directions
North = 1,
The above is a C# definition for an enumeration called Directions that has 4 main values.
Now, to bind the above enumeration values to a DropDownList we need the following:
// Loop through the Directions' items
// and add them item by item into the DropDownList
ListItem item = null;
string directionNames = Enum.GetNames(typeof(Directions));
for (int x = 0; x < directionNames.Length - 1; x++)
// Create the item
item = new ListItem(
// Add the item to the list of items
// inside the DropDownList
You notice in the code above, to retrieve the names of all the items in the enumeration, you make use of the Enum.GetNames() method. Once you have all the items in the enumeration as String values, you loop through the list of values of the enumeration.
For each value, you create a new ListItem class passing to it the:
Once the ListItem is created, simply add it to the collection of Items of the DropDownList placed in the HTML markup.
The DropDownList is defined as follows:
<asp:DropDownList ID="ddlDirections" runat="server" AppendDataBoundItems="true" >
<asp:ListItem Text=" .. Choose a Direction .." Value="-1" Selected="True"/>
This is all what you need to do to bind a DropDownList to an enumeration!
Hope it helps,
Tags: ASP.NET 2.0, ASP.NET 3.5
Powered by BlogEngine.NET 18.104.22.168 - Theme created by Tommaso Baldovino, adapted by onesoft