---
title: "How to Use DropDownList Dynamically Using Ajax"  
description: "How to Use DropDownList Dynamically Using Ajax"  
author: "Anonymous User"  
published: 2015-11-26  
updated: 2015-11-26  
canonical: https://www.mindstick.com/forum/33645/how-to-use-dropdownlist-dynamically-using-ajax  
category: "asp.net"  
tags: ["asp.net", "ajax", "jquery"]  
reading_time: 2 minutes  

---

# How to Use DropDownList Dynamically Using Ajax

I want to use [DropDownList](https://www.mindstick.com/articles/324837/how-to-bind-dropdownlist-in-mvc-core-from-database-using-entity-framework) Dynamically Using [Ajax](https://www.mindstick.com/articles/1541/check-availability-of-user-name-or-email-using-asp-dot-net-ajax-and-jquery) in [asp.net](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) please help me

## Replies

### Reply by Anonymous User

HTML dropdown list statically is very easy. It is done directly using a “select” tag , but when we have a requirement to add the data in HTML dropdownlist dynamically then the things change. At that time we must load the data from the database.

```
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UsingAjaxDropDown.aspx.cs" Inherits="Forumasp.UsingAjaxDropDown" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title>     <script src="Scripts/jquery-2.1.4.js"></script></head><body>     <script>         $(function () {             $.ajax({                 type: "POST",                                  url: "UsingAjaxDropDown.aspx/GetData",                 data: {},                 contentType: "application/json; charset=utf-8",                 dataType: "json",                 asnyc: false,                                 success: function (data) {                     var result = data['d'];                     for (var i = 0; i < result.length; i++) {                         console.log(result[i].Emp_Name);                         var opt = new Option(result[i].Emp_Name);                         $("#opemp").append(opt);                     }                 }             })         });        </script>    <form id="form1" runat="server">    <div>     <div>              <label>Select Employee :</label>          </div>          <div>              <select class="form-control" id="opemp" style="width:200px;">                  <option selected="selected">Select</option>              </select>          </div>      </div>    </form></body></html>
```

```
using System;using System.Collections.Generic;using System.Configuration;using System.Data;using System.Data.SqlClient;using System.Linq;using System.Web;using System.Web.Services;using System.Web.UI;using System.Web.UI.WebControls;namespace Forumasp{    public partial class UsingAjaxDropDown : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {        }        [WebMethod]        public static List<Employee> GetData()        {            List<Employee> Emp = new List<Employee>();            DataTable dt = new DataTable();            string constr = ConfigurationManager.ConnectionStrings["forumConnectionString"].ToString(); // connection string            SqlConnection con = new SqlConnection(constr);            con.Open();            SqlCommand com = new SqlCommand("select *from Employee", con); // table name             SqlDataAdapter da = new SqlDataAdapter(com);            DataSet ds = new DataSet();            da.Fill(ds);            dt = ds.Tables[0];            Emp = (from DataRow row in dt.Rows                   select new Employee                   {                       Emp_ID = Convert.ToInt32(row["Emp_ID"]),                       Emp_Name = row["Emp_Name"].ToString(),                       Emp_Sal =Convert.ToDecimal( row["Emp_Sal"])                   }).ToList();            return Emp;        }    }    public class Employee    {        public int Emp_ID { get; set; }        public string Emp_Name { get; set; }        public decimal Emp_Sal { get; set; }    }}
```

![How to Use DropDownList Dynamically Using Ajax](https://www.mindstick.com/mindstickforums/c54d9c98-080e-481c-aa5b-d0c86e46f437/images/f42dedb8-f746-4aab-9ae5-53b91ac00d7d.png)


---

Original Source: https://www.mindstick.com/forum/33645/how-to-use-dropdownlist-dynamically-using-ajax

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
