コード例 #1
0
        private void PopulateEmpList()
        {
            LearnEFEntities db = new LearnEFEntities();

            List <Employee> empList = db.SearchEmployee(txtSrchFirstName.Text, txtSrchCity.Text).ToList();

            ddlEmployee.DataSource     = empList;
            ddlEmployee.DataValueField = "EmpId";
            ddlEmployee.DataTextField  = "FirstName";
            ddlEmployee.DataBind();

            ddlEmployee.Items.Insert(0, new ListItem("--Add New--", "0"));

            //bind grid
            GridView1.DataSource = empList;
            GridView1.DataBind();
        }
コード例 #2
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            //below code does not work.....
            LearnEFEntities db  = new LearnEFEntities();
            int             ret = db.SearchEmployee(txtFirstNameSearch.Text, txtCitySearch.Text);

            db.Dispose();

            using (var context = new LearnEFEntities())
            {
                var firstNameParameter = new SqlParameter("@FirstName", txtFirstNameSearch.Text);
                var cityParameter      = new SqlParameter("@City", txtCitySearch.Text);
                var result             = context.Database
                                         .SqlQuery <Employee>("SearchEmployee @FirstName, @City", firstNameParameter, cityParameter)
                                         .ToList();
                //bind grid
                GridSearch.DataSource = result;
                GridSearch.DataBind();
            }
        }
コード例 #3
0
ファイル: Default.aspx.cs プロジェクト: sloww/learnEF
        private void PopulateEmpList()
        {
            LearnEFEntities db = new LearnEFEntities();

            List<Employee> empList = db.SearchEmployee(txtSrchFirstName.Text, txtSrchCity.Text).ToList();

            ddlEmployee.DataSource = empList;
            ddlEmployee.DataValueField = "EmpId";
            ddlEmployee.DataTextField = "FirstName";
            ddlEmployee.DataBind();

            ddlEmployee.Items.Insert(0, new ListItem("--Add New--", "0"));

            //bind grid
            GridView1.DataSource = empList;
            GridView1.DataBind();
        }