Click here to Skip to main content
15,889,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using following code to bind data in grid view dropdownlist
C#
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {            
                  
                CheckBox CHKBOX = (e.Row.FindControl("Released") as CheckBox);
                CheckBox CHKBOX1 = (e.Row.FindControl("Released1") as CheckBox);
                    DropDownList ddlEmployee = (e.Row.FindControl("ddlEmp") as DropDownList);
                    DropDownList ddlEmployee2 = (e.Row.FindControl("ddlEmp2") as DropDownList);
                    var emp1 = _service.GetEmployeeDutyByEmployee_Id(MyUser.Employee_Id).LastOrDefault();
                    var EmpList = _service.GetAllEmployeeDuty().OrderByDescending(x => x.EndDate).GroupBy(x => x.Employee_Id).Select(x => x.First()).ToList();
                    var empList = EmpList.Where(X => X.ToSector_Id == emp1.ToSector_Id).ToList();
                    ddlEmployee.Bind(empList, "EmployeeIdName", "Employee_Id");
                    ddlEmployee2.Bind(empList, "EmployeeIdName", "Employee_Id");
                  
            }
        }

and use following code to save the values
C#
protected void ddlEmp_SelectedIndexChanged(object sender, EventArgs e)
           {
               Entities entities = new Entities();

               Control row = ((Control)sender).NamingContainer;
               DropDownList ddlEmp = (DropDownList)row.FindControl("ddlEmp");
               DropDownList ddlEmp2 = (DropDownList)row.FindControl("ddlEmp2");
               Label lblPointName = (Label)ddlEmp.NamingContainer.FindControl("lblPointName");
               Label lblPointName1 = (Label)ddlEmp.NamingContainer.FindControl("lblPointName1");
               string Emp1 = ddlEmp.SelectedValue;
               string Emp2 = ddlEmp2.SelectedValue;
               string pointname = lblPointName.Text;
               string pointname1 = lblPointName1.Text;

                   var PointIdByName = (from mdp in entities.SectorWisePoints.Where(x => x.Name == pointname) select mdp).Single();
                   var EmployeeById = (from ebi in entities.ModifiedNames.Where(x => x.BeltNo == Emp1) select ebi).Single();
                   CTP.HRMS.Business.DailyManualRoaster dmr = new Business.DailyManualRoaster();
                   dmr.SectorWisePoint_Id = PointIdByName.Id;
                   dmr.Employee_Id = EmployeeById.BeltNo;
                   dmr.ManDailyRoasterDate = DateTime.Now;
                   dmr.Sector_Id = 1;
                   _service.InsertDailyManualRoaster(dmr);



               }

1.i want that when an employee is saved once it will remove employee from the list.
2.i have a checkbox along each row when user click on this box the employee against this row that is save already ,will be deleted from database and again add to list of dropdown?
Posted

1 solution

- Delete or add employee from-to the db.
- After success, just get the employees from db once more.
- Bind the updated employees from db to the dropdownlist datasource and you are done.
 
Share this answer
 
v2
Comments
Sajid227 21-Sep-15 1:00am    
how can i do it with grid view?where remove of employee is done i n selected index change ,and data is bounding on ondatabounding event?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900