Simple way to bind asp:DropDownList.

Here we discussing about how to simply bind DropDownList.

Step 1: Add a page in your project.

Step 2: Add a DropdownList to your .aspx that you added in your project.


          <asp:DropDownList ID="ddlEmpName" runat="server">                                                                       </asp:DropDownList>

Step 3: Now Press F7 key or GoTo Code page of relevant .aspx page.

Step 4: Create a method of bind DropDownList as below:

protected void bindEmployee()
{
            DataTable dtEmp = new DataTable();
            clsLkupEmployee objEmp = new clsLkupGender();
            dtEmp = objEmp.GetData();
            ddlEmpName.DataSource = dtGender;
            ddlEmpName.DataTextField = dtGender.Columns["EmployeeName"].ToString();
            ddlEmpName.DataValueField = dtGender.Columns["EmployeeID"].ToString();
            ddlEmpName.DataBind();
            ddlEmpName.Items.Insert(0, new ListItem("--Select Gender--", "0"));
            ddlEmpName.SelectedValue = "0";

        }

Step 5: Call this method on PageLoad.
Step 6: Now run the project.
Here you see the with EmplyeeName.
Newest