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.
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
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
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.