Best practice for binding drop down lists in 3-tier architecture

1.2k views Asked by At

I'm a beginner in using the 3-tier approach in development, i got many drop down lists in my application each consisting of 4 or 5 choices. If i stored this data in my database, then according to my understanding of 3-tier approach, i need to create a Data access class and a business class for each of the lists. This means i need to create almost 40 classes for 20 drop down lists, this surely does not sound practical.

Is there a better way to design drop down lists or to store the DDL data in my application ?

2

There are 2 answers

0
Mox Shah On

You can have a generic binding class as following.

/// <summary>
    /// Common DropDown model
    /// </summary>
    public class SelectListModel
    {
        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>
        /// The value.
        /// </value>
        public int Value { get; set; }

        /// <summary>
        /// Gets or sets the item.
        /// </summary>
        /// <value>
        /// The item.
        /// </value>
        public string Item { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is selected.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is selected; otherwise, <c>false</c>.
        /// </value>
        public bool IsSelected { get; set; }
    }

You can bind any dropdown data into this model and return it to the view.

0
senthilkumar2185 On
private void DropwonlistBind(DropDownList DDLName)
{

DDLName.Datasource="YourSouce";
DDLName.DataTextField="TextField";
DDLName.DataValueField="IDField";
DDLName.Databind();

}