Sajid Hussain

Sajid Hussain

  • 1.2k
  • 514
  • 100.7k

how to create multiple rows base on database table value

Sep 2 2015 4:16 AM
i have go through many article in google,but its not up to my point,
i want in my gridview following requirements ,
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
Id    Name
 1     xxx 
2     yyy 
3     zzz 
IN my database table Employee
Hide Copy Code
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
Hide Expand Copy Code
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