How To Bind Enum To DropDownList

This will set the dropdown text to the enum’s description and the value (int) from the enum.

SeverityType.cs (Enum)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace com.aep.ehap.bl
{
    /// <summary>
    /// Defines a type of Severity.
    /// </summary>
    public enum SeverityType
    {
        [Description("1 - Injury free event, first aid, non recordable")]
        InjuryFreeEvent = 0,

        [Description("2 - Medical, restricted duty/transfer = <2 days")]
        MedResDutyLessTwoDays = 1,

        [Description("3 - Restricted duty/transfer = <= 10 days")]
        MedResDutyLessTenDays = 2,

        [Description("4 - Restricted duty/transfer = <30 days")]
        MedResDutyLessThirtyDays = 3,

        [Description("5 - Restricted duty/transfer =<60 days")]
        MedResDutyLessSixtyDays = 4,

        [Description("6 - Complete disabling or fatality")]
        DisablingOrFatality = 5

    }
}

Page CodeBehind

          
            // Bind the Dropdown lists

            // Default first value in dropdown
            this.ddlPotentialSeverity.Items.Add(new ListItem() { Text = "Select one...", Value = "-1" });

            // Retrieve list of SeverityType's from enum
            List<SeverityType> SeverityTypes = new List<SeverityType>((SeverityType[])Enum.GetValues(typeof(SeverityType)));

            this.ddlPotentialSeverity.Items.AddRange(
                 (from severityType in SeverityTypes
                  select new ListItem()
                  {
                      Value = severityType.ToString(),
                      Text = Util.GetEnumDescription(severityType)
                  }).ToArray());

Util.cs (GetEnumDescription)


        /// <summary>
        /// Gets the enum description given enum value
        /// </summary>
        /// <param name="value">The value from enum.</param>
        /// <returns></returns>
        public static string GetEnumDescription(Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());
            DescriptionAttribute[] attributes =
                  (DescriptionAttribute[])fi.GetCustomAttributes(
                  typeof(DescriptionAttribute), false);
            return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
        }

How To Embed A UserControl In A Repeater

Page ASPX

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="ControlInRepeater.aspx.cs" Inherits="com.dereksandbox.ui.Pages.ControlInRepeater" %>

<%@ Register Src="../Controls/EmbeddedControl.ascx" TagName="EmbeddedControl" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Repeater ID="Repeater1" runat="server" 
        onitemdatabound="Repeater1_ItemDataBound">
        <ItemTemplate>
            <uc1:EmbeddedControl ID="EmbeddedControl1" runat="server" />
        </ItemTemplate>
    </asp:Repeater>
</asp:Content>

Page Code Behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.dereksandbox.bl.ServiceManagers;
using com.dereksandbox.bl.Entities;
using com.dereksandbox.ui.Controls;

namespace com.dereksandbox.ui.Pages
{
    public partial class ControlInRepeater : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Repeater1.DataSource = PersonServiceManager.getPeople();
            Repeater1.DataBind();
        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            
            
            // This event is fired each time a new Person control is created in the repeater

            EmbeddedControl ctrl = (EmbeddedControl)e.Item.FindControl("EmbeddedControl1");
            ctrl.Person = (PersonEntity)e.Item.DataItem;           
           

        }
    }
}

Control ASCX

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EmbeddedControl.ascx.cs"
    Inherits="com.dereksandbox.ui.Controls.EmbeddedControl" %>
<asp:Label ID="lblName" runat="server" Text="lblName"></asp:Label>
<asp:Label ID="lblWeight" runat="server" Text="lblAge"></asp:Label>
<br />

Control CodeBehind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.dereksandbox.bl.Entities;

namespace com.dereksandbox.ui.Controls
{
    public partial class EmbeddedControl : System.Web.UI.UserControl
    {
        public PersonEntity Person { get; set; }


        protected void Page_Load(object sender, EventArgs e)
        {
            lblName.Text = Person.Name;
            lblWeight.Text = Person.Weight.ToString();
          
        }

      
    }
}

How to Hide/Show DIVs Client-Side Using JavaScript


<!-- Hazard & Controls -->
<a id="linkHazardsAndControls" class="HazardsAndControlslink" href="Javascript:void(0)"
    onclick="ShowHazardsAndControls(this);">Hazards &amp; Controls</a>


<div id="DIVHazardAndControls" style="display: none">
    What you want to hide or show in here
</div>


<script language="javascript" type="text/javascript">
    function ShowHazardsAndControls(linkReference) {
        if (linkReference.innerHTML == 'Hazards &amp; Controls') {
            document.getElementById('DIVHazardAndControls').style.display = 'inline';
            linkReference.innerHTML = 'Hide Hazards &amp; Controls';
        }
        else {
            document.getElementById('DIVHazardAndControls').style.display = 'none';
            linkReference.innerHTML = 'Hazards &amp; Controls';
        }
    } 
</script>

 

Deploying / Publishing ASP.NET Sites

  1. Delete all files from UI’s project /bin
  2. Set to Release mode configuration
  3. Build | Clean Solution
  4. Build | Build Solution
  5. Right click on UI project and select Publish
  6. Specify target location (Disk path: c:\publishedSite)
  7. Click Publish
  8. Upload all files in target location to FTP

Be cognizant of configuration files between environments (example web.config)

You can exclude /lib as well.