hi all,
i am using vs 2010 and sql server
i have gridview on my web form and my requirement is make the grid view updateable, deleteable using linq.....
below i have written code for the same but value is taken by the code is the old data only.......
please have a look and help me.........
protected
void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string uniq=((TextBox)GridView1.Rows[e.RowIndex].Cells[9].Controls[0]).Text;
string firstname = ((TextBox
)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
string middlename = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
string lastname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
string department = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
string designation = ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text;
string mobnumber = ((TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[0]).Text;
string dob = ((TextBox)GridView1.Rows[e.RowIndex].Cells[8].Controls[0]).Text;
DataClasses1DataContext obj = new DataClasses1DataContext();
var update = obj.Employees.Single(s => s.Emp_Code == uniq);
update.Emp_FirstName = firstname;
update.Emp_MiddleName = middlename;
update.Emp_LastName = lastname;
update.Department = department;
update.Designation = designation;
update.MobileNumber = mobnumber;
update.DOB = dob;
try
{
obj.SubmitChanges();
Response.Write(
"Updated Successfully");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
LoadGridData();
GridView1.EditIndex = -1;
}
the above code is updating but the old value only.......