Posts

Showing posts with the label Web Forms

Bind Enum Type to A DropDownList Control In ASP.NET C#

Image
Suppose you have an enum type like the one below, and you want to bind the enum type to a DropDownList control in a Web Forms application.  How would you do this?  There's an easy way to do this with just a few lines of code.  You'll be amaze at how simple it is. First of all here is our markup code in our .aspx page <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Sandbox.Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList> </div> </form> </body> </html> Now let's define our enum type, the last value is 400 just to confirm that the Dr...