I have a gridview there i foreach all row in the grid and for each cell i add the values to the columns in the database, it seems when i save the values in the cells looses , because in sql i have no values only the column the "and they are empty", after debbuging the column in the datbase has null in all the columns.
how could i solve this?
foreach (GridViewRow gvRowAssigment in GridViewAllAssigments.Rows)
{
var emp_assig_ref = new EMPLOYEES_ASSIGMENT_REFERENCE();
emp_assig_ref.reference_name = gvRowAssigment.Cells[8].Text;
emp_assig_ref.reference_id = new Random().Next();
var emp_assig_teh = new EMPLOYEES_ASSIGMENT_TECHNOLOGY();
emp_assig_teh.technology_name = gvRowAssigment.Cells[7].Text;
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].Text;
emp_assig_tools.assigment_tools_id = new Random().Next();
var emp_assigment = new EMPLOYEES_ASSIGNMENT
{
from_date = gvRowAssigment.Cells[0].Text,
to_date = gvRowAssigment.Cells[1].Text,
area = gvRowAssigment.Cells[2].Text,
sector = gvRowAssigment.Cells[3].Text,
company_name = gvRowAssigment.Cells[4].Text,
description = gvRowAssigment.Cells[5].Text,
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();
And for adding textbox values to gridview on button i use this
private void addassigment()
{
if (Session["DataTable"] != null)
{
dt = (DataTable) Session["DataTable"];
}
else
{
DataColumn cl = new DataColumn("From");
dt.Columns.Add(cl);
cl = new DataColumn("To");
dt.Columns.Add(cl);
DataColumn cl1 = new DataColumn("Area");
dt.Columns.Add(cl1);
cl1 = new DataColumn("Sector");
dt.Columns.Add(cl1);
DataColumn cl2 = new DataColumn("CompanyName");
dt.Columns.Add(cl2);
cl2 = new DataColumn("Description");
dt.Columns.Add(cl2);
DataColumn cl3 = new DataColumn("Tools");
dt.Columns.Add(cl3);
cl3 = new DataColumn("Technology");
dt.Columns.Add(cl3);
DataColumn cl4 = new DataColumn("References");
dt.Columns.Add(cl4);
}
string sToolsValue = string.Empty;
string sTechnologyvalue = string.Empty;
DataRow dr = dt.NewRow();
dr[0] = TextBoxFrom.Text;
dr[1] = TextBoxTo.Text;
dr[2] = TextBoxArea.Text;
dr[3] = TextBoxSector.Text;
dr[4] = TextBoxCompanyName.Text;
dr[5] = TextBoxDescription.Text;
dr[8] = TextBoxReferences.Text;
for (int i = 0; i < ListBoxAssignmentTools.Items.Count; i++)
{
sToolsValue += ListBoxAssignmentTools.Items[i];
}
for (int i = 0; i < ListBoxAssignmentTechnology.Items.Count; i++)
{
sTechnologyvalue += ListBoxAssignmentTechnology.Items[i];
}
dr[6] = sToolsValue;
dr[7] = sTechnologyvalue;
dt.Rows.Add(dr);
Session["DataTable"] = dt;
GridViewAllAssigments.DataSource = dt;
GridViewAllAssigments.DataBind();
and here is the code behind for the gridivew
<Columns>
<asp:TemplateField HeaderText="From">
<ItemTemplate>
<asp:Label ID="LabelFrom" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"From")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="To">
<ItemTemplate>
<asp:Label ID="LabelTo" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"To")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Area">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Area")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sector">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Sector")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Company name">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"CompanyName")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Description")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tools">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Tools")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Technology">
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Technology")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="References">
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"References")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
[Edit - further code from the OP and have added WCF to the tags]
public void setEmployee(string attachmentUrl)
{
var db = new knowitCVdbEntities();
var emp = new EMPLOYEE
{
firstname = TextBoxFirstName.Text,
lastname = TextBoxLastName.Text,
about = TextBoxAboutYou.Text,
phone = TextBoxPhone.Text,
position = TextBoxPosition.Text,
email = TextBoxEmail.Text,
username = TextBoxUsername.Text,
date_of_birth = TextBoxDateOfBirth.Text,
image = attachmentUrl,
document_cv = "Document Cv"
};
foreach (var languages in ListBoxLanguages.Items)
{
var emplanguages = new EMPLOYEE_LANGUAGES();
{
emplanguages.language_name = languages.ToString();
}
emp.EMPLOYEE_LANGUAGES.Add(emplanguages);
}
foreach (var certifications in ListBoxCertifications.Items)
{
var cert = new EMPLOYEES_CERTIFICATIONS();
{
cert.certificate_name = certifications.ToString();
}
emp.EMPLOYEES_CERTIFICATIONS.Add(cert);
}
foreach (var courses in ListBoxCourses.Items)
{
var course = new EMPLOYEES_COURSES();
{
course.course_name = courses.ToString();
}
emp.EMPLOYEES_COURSES.Add(course);
}
foreach (var prevworkex in ListBoxPreviousWorkExperience.Items)
{
var prevwork = new EMPLOYEES_PREV_WORK_EX();
{
prevwork.prev_work_name = prevworkex.ToString();
}
emp.EMPLOYEES_PREV_WORK_EX.Add(prevwork);
}
foreach (var businnesknow in ListBoxBusinnesKnowLedge.Items)
{
var businessknowledge = new EMPLOYEES_BUSINESS_KNOWLEDGE();
{
businessknowledge.businees_knowledge_name = businnesknow.ToString();
}
emp.EMPLOYEES_BUSINESS_KNOWLEDGE.Add(businessknowledge);
}
foreach (var educ in ListBoxEducation.Items)
{
var education = new EMPLOYEES_EDUCATIONS();
{
education.employee_education_name = educ.ToString();
}
emp.EMPLOYEES_EDUCATIONS.Add(education);
}
foreach (var lstdatabase in ListBoxDataBase.Items)
{
var mySkill = new TECHNICAL_SKILLS();
{
mySkill.skill_name = lstdatabase.ToString().Split('-')[0];
mySkill.skill_type = LabelDataBase.Text;
mySkill.technical_skill_id = new Random().Next();
}
var myLevel = new TECHNICAL_SKILL_LEVEL();
{
myLevel.skill_level = lstdatabase.ToString().Split('-')[1];
myLevel.technical_skill_level_id = new Random().Next();
}
var skill = new EMPLOYEES_TECHNICAL_SKILLS();
{
skill.employee_id = emp.employee_id;
skill.TECHNICAL_SKILL_LEVEL = myLevel;
skill.TECHNICAL_SKILLS = mySkill;
skill.t