public class DropDownlistController : Controller
{
// GET: DropDownlist
public ActionResult DropDownControl()
{
Dropdownlist multi_Dropdownlist = new Dropdownlist
{
custlist = GetCustomerList(),
emplist = GetEmployeeList()
};
return View(multi_Dropdownlist);
}
public List<Customer_list> GetCustomerList()
{
var connection = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
SqlConnection con = new SqlConnection(connection);
SqlCommand cmd = new SqlCommand("Select customerId,FirstName as Name From Customers", con);
con.Open();
SqlDataReader idr = cmd.ExecuteReader();
List<Customer_list> customers = new List<Customer_list>();
if (idr.HasRows)
{
while (idr.Read())
{
customers.Add(new Customer_list
{
custId = Convert.ToInt32(idr["customerId"]),
custName = Convert.ToString(idr["Name"]),
});
}
}
con.Close();
return customers;
}
public List<Employee_list> GetEmployeeList()
{
var connection = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
SqlConnection con = new SqlConnection(connection);
SqlCommand cmd = new SqlCommand("Select * From Employees", con);
con.Open();
SqlDataReader idr = cmd.ExecuteReader();
List<Employee_list> Employees = new List<Employee_list>();
if (idr.HasRows)
{
while (idr.Read())
{
Employees.Add(new Employee_list
{
Empid = Convert.ToInt32(idr["EmpoyeeId"]),
EmpName = Convert.ToString(idr["EmpName"]),
});
}
}
con.Close();
return Employees;
}
}