Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have go through many article in google,but its not up to my point,
i want in my gridview following requirements ,
C#
s.no    pointsName     Employee   IsOK
1       XXX(TEXTBOX)     EMP1(DDL)  TRUE(CHECKBOX)
2        YYY(TEXTBOX)     EMP1(DDL)  TRUE(CHECKBOX 
3         zzz(TEXTBOX)     EMP1(DDL)  TRUE(CHECKBOX

IN my database table Dutypoint
SQL
Id    Name
1     xxx
2     yyy
3     zzz

IN my database table Employee
SQL
Id    Name
1     xxx
2     yyy
3     zzz

i want to create rows in gridview base on point,and display name of point in the text box.what i so far tried is as follow
C#
DataTable dt = new DataTable();

        DataRow dr = null;

       
        var SecPoint = _service.GetAllDutyPoint().ToList();
        foreach (var point in SecPoint)
        {
            for (int I = 1; I <= point.NoOfMinEmployes; I++)
            {
                ////Define the Columns
                //dr["RowNumber"] = I + 1;
                //dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));

                //dt.Columns.Add(new DataColumn("Column1", typeof(string)));

                //dt.Columns.Add(new DataColumn("Column2", typeof(string)));

                //dt.Columns.Add(new DataColumn("Column3", typeof(string)));

                //dr = dt.NewRow();

                

                //dt.Rows.Add(dr);
                ////Store the DataTable in ViewState

                //ViewState["CurrentTable"] = dt;

                ////Bind the DataTable to the Grid

                //Gridview1.DataSource = dt;

                //Gridview1.DataBind();
                ////Extract and Fill the DropDownList with Data
                //TextBox txtbox = (TextBox)Gridview1.Rows[0].Cells[1].FindControl("TextBox12");
                //DropDownList ddl1 = (DropDownList)Gridview1.Rows[0].Cells[2].FindControl("ddlEmp");
                //TextBox txtbox1 = (TextBox)Gridview1.Rows[0].Cells[3].FindControl("TextBox13");
                //DropDownList ddl2 = (DropDownList)Gridview1.Rows[0].Cells[4].FindControl("ddlEmp2");
                //FillDropDownList(ddl1);
                //FillDropDownList(ddl2);

 private void FillDropDownList(DropDownList ddl)
    {

        
        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();
        ddl.Bind(empList, "EmployeeIdName", "Employee_Id");
    }   
    }

its just return one row
Posted
Comments
Maciej Los 2-Sep-15 9:25am    
Not clear. Based on what relationship you want to join employee with point name?
Sajid227 3-Sep-15 0:44am    
one point has just one employee at one time?
Maciej Los 3-Sep-15 1:41am    
And... What field in Employee table is related to DutyPoint table? I don't see...
ramyajaya 2-Sep-15 16:05pm    
In your query u have selected x.first () obviously it will return one row right?

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