Thursday, 3 December 2015

How to bind dropdown with multiple columns using entity framework?



Problem:

We have to bind the table to the dropdown where we need the complete name as the text value of dropdown and emp_id as datavalue.



The name of dropdownlist is ddlRequestTo and the entity database object named context with tbl_employeePersonal


Solution:

private void bindRequestTo()

{
ddlRequestTo.DataSource = (from emp in context.tbl_employeePersonal select new { FullName = emp.emp_firstName + " " + emp.emp_middleName + " " + emp.emp_lastName, emp.emp_Id}).ToList();
ddlRequestTo.DataTextField = "FullName";
ddlRequestTo.DataValueField = "emp_Id";
ddlRequestTo.DataBind();
ddlRequestTo.Items.Insert(0, "--Send Request To--");
}




No comments:

Post a Comment