Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Smarter DropDownList Controls

This is more of an ASP.NET item than Community Server, though you see it in CS quite a bit.  It's another case for me as a developer doing a lot of CS customization able to say, "I like how these guys think!"

By "Smarter DropDownList Controls" I'm referring to ASP.NET control classes that derive from the System.Web.UI.Controls.DropDownList class, bringing additional functionality, re-useability and more efficient development.

One of my CS projects puts a Jobs Management twist on the community concept and thus I have an occasional need to display employees in a dropdown select list.  

I can add an EmployeeDropDownList control on a web page with


<DBVT:EmployeeDropDownList id="employeeList" runat="server" DisplayNotAvailableUser="true"  ActiveOnly="true" Width="235px" />


and I'm done.  All of the logic is in the EmployeeDropDownList class.  Notice the DisplayNotAvailableUser and ActiveOnly properties.  They serve when building the query in the EmployeeDropDownList CreateChildControls() method.

protected override void CreateChildControls()
{
    base.CreateChildControls();
    if (!Page.IsPostBack)
    {

        StringBuilder sb = new StringBuilder();
        sb.Append("select * from dbvt_job_employees where ");

        string _ifActiveOnly = "active = 1 ";
        if (!ActiveOnly)
            _ifActiveOnly = "active = 0 ";
        sb.Append(_ifActiveOnly);

        string _ifDisplayNotAvailableUser = string.Empty;
        if (DisplayNotAvailableUser)
            _ifDisplayNotAvailableUser = " or employeeID = 1 ";

        sb.Append(_ifDisplayNotAvailableUser); 
        sb.Append("order by employeeName");

        List<JobEmployee> _JobEmployees = Jobs.GetEmployees(sb.ToString());

        foreach (JobEmployee jobEmployee in _JobEmployees)
        {
            Items.Add(new ListItem(jobEmployee.EmployeeName,
                  jobEmployee.EmployeeID.ToString()));
        }
    }

}

Comments (0) | Post RSS RSS comment feed

Posted on 8/18/2007 10:50:39 AM by Dave Burke
Categories: .NET | Community Server
Tags:

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke