private void BindDepartment() { var source = GetDepartmentData(); DepartmentDropDown.DataSource = source; DepartmentDropDown.DataTextField = "Text"; DepartmentDropDown.DataValueField = "Id"; DepartmentDropDown.DataBind(); }
private void InitializeDropdowns() { var userId = Context.User.Identity.GetUserId(); var user = _userCache.Get(userId); var companyId = user.CompanyId; DepartmentDropDown.DataSource = _departmentDal.GetByCompany(companyId).ToSafeList(); DepartmentDropDown.DataBind(); RefreshServers(); }
public void LoadDepartmentDropDownList() { try { string connectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString; using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("SELECT DepartmentName from Department where ([CompanyName]=@CompanyName)", con); con.Open(); cmd.Parameters.AddWithValue("@CompanyName", CompanyDropDown.SelectedItem.Value); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); // fill dataset DepartmentDropDown.DataValueField = ds.Tables[0].Columns["DepartmentName"].ToString(); // to retrive specific textfield name DepartmentDropDown.DataSource = ds.Tables[0]; //assigning datasource to the dropdownlist DepartmentDropDown.DataBind(); //binding dropdownlist } } catch (Exception ex) { Response.Write(ex.Message); } }