Click here to Skip to main content
15,898,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
foreach (GridViewRow gvRowAssigment in GridViewAllAssigments.Rows)
            {
                var emp_assig_ref = new EMPLOYEES_ASSIGMENT_REFERENCE();
                emp_assig_ref.reference_name = gvRowAssigment.Cells[8].ToString();
                emp_assig_ref.reference_id = new Random().Next();

                var emp_assig_teh = new EMPLOYEES_ASSIGMENT_TECHNOLOGY();
                emp_assig_teh.technology_name = gvRowAssigment.Cells[7].ToString();
                emp_assig_teh.assigment_technology_id = new Random().Next();

                var emp_assig_tools = new EMPLOYEES_ASSIGMENT_TOOLS();
                emp_assig_tools.tools_name = gvRowAssigment.Cells[6].ToString();
                emp_assig_tools.assigment_tools_id = new Random().Next();

                var emp_assigment = new EMPLOYEES_ASSIGNMENT
                                        {
                                            from_date = gvRowAssigment.Cells[0].ToString(),
                                            to_date = gvRowAssigment.Cells[1].ToString(),
                                            area = gvRowAssigment.Cells[2].ToString(),
                                            sector = gvRowAssigment.Cells[3].ToString(),
                                            company_name = gvRowAssigment.Cells[4].ToString(),
                                            description = gvRowAssigment.Cells[5].ToString(),


                                            employee_id = emp.employee_id,
                                            assigment_id = new Random().Next(),


                                            EMPLOYEES_ASSIGMENT_TOOLS = emp_assig_tools,

                                            assigment_tools_id = emp_assig_tools.assigment_tools_id,

                                            EMPLOYEES_ASSIGMENT_TECHNOLOGY = emp_assig_teh,
                                            assigment_technology_id = emp_assig_teh.assigment_technology_id,

                                            EMPLOYEES_ASSIGMENT_REFERENCE = emp_assig_ref,
                                            reference_id = emp_assig_ref.reference_id
                                        };


                emp.EMPLOYEES_ASSIGNMENT.Add(emp_assigment);
 }




            db.AddToEMPLOYEES(emp);
            db.SaveChanges();
        }


It dont saves the values that i have written in the textboxes in the sql , i get this
System.Web.UI.WebControls.DataControlFieldCell
Posted
Updated 23-Mar-13 4:11am
v2

1 solution

Try
C#
gvRowAssigment.Cells[n].Value.ToString()
Without the .Value you are converting the whole DataControlFieldCell to a string, which gives you the name of the type rather than the number (or whatever) it contains.
 
Share this answer
 
Comments
Kurac1 23-Mar-13 10:50am    
There is no .Value
Kurac1 23-Mar-13 10:50am    
i have tryed with .Text but i dont get any values then
Kurac1 23-Mar-13 10:50am    
and when using text.tostring(); the //Tostring(); is redundant so i dont need it

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