The following is the code for update event and method :
public void updateRow(string itemID, string firstName, string lastName, string age, string eAddress, string department, string manager, string gender, string salary)
{
ClientContext clientContext = new ClientContext("https://xyz.xyz.com/sites/xyz/TrainingSite/");
try
{
SP.List oList = clientContext.Web.Lists.GetByTitle("Employees");
clientContext.Load(oList);
SP.CamlQuery camlQuery = new SP.CamlQuery();
camlQuery.ViewXml = @"<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + itemID + "</Value></Eq></Where></Query>";
SP.ListItemCollection itemInfo = oList.GetItems(camlQuery);
clientContext.Load(itemInfo);
clientContext.ExecuteQuery();
foreach (SP.ListItem item in itemInfo)
{
if (itemID == item["ID"].ToString())
{
item["Title"] = firstName;
item["Last_x0020_Name"] = lastName;
item["u5ib"] = age;
item["Address"] = eAddress;
//Department column
//item["Department"] = department;
FieldLookupValue deptItem = new FieldLookupValue();
deptItem.LookupId = Convert.ToInt32(1); //department should be department list item ID because its a lookup ID
item["Department"] = deptItem;
//Manager column
//item["Manager"] = manager;
FieldLookupValue mgrItem = new FieldLookupValue();
mgrItem.LookupId = Convert.ToInt32(1);//giving 1 displays only the first item of the list [issue]
item["Manager"] = mgrItem;
item["Gender"] = gender;
item["Salary"] = salary;
item.Update();
break;
}
}
clientContext.ExecuteQuery();
}
catch (Exception e)
{
throw e;
}
}
protected void gridview_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//Accessing Edited values from the GridView
TextBox itemID = (TextBox)gridview.Rows[e.RowIndex].Cells[0].FindControl("VJ"); //ID
TextBox firstName = (TextBox)gridview.Rows[e.RowIndex].Cells[1].FindControl("TextBoxEditFirstName"); //firstName
TextBox lastName = (TextBox)gridview.Rows[e.RowIndex].Cells[2].FindControl("TextBoxEditLastName"); //lastName
TextBox age = (TextBox)gridview.Rows[e.RowIndex].Cells[3].FindControl("TextBoxEditAge"); //age
TextBox eAddress = (TextBox)gridview.Rows[e.RowIndex].Cells[4].FindControl("TextBoxEditAddress"); //eAddress
//TextBox department = (TextBox)gridview.Rows[e.RowIndex].Cells[4].FindControl("ddlDepartment"); //department
//TextBox manager = (TextBox)gridview.Rows[e.RowIndex].Cells[5].FindControl("ddlManager"); //manager
DropDownList department = (DropDownList)gridview.Rows[e.RowIndex].Cells[5].FindControl("ddlDepartment"); //department
DropDownList manager = (DropDownList)gridview.Rows[e.RowIndex].Cells[6].FindControl("ddlManager"); //manager
TextBox gender = (TextBox)gridview.Rows[e.RowIndex].Cells[7].FindControl("TextBoxEditGender"); //gender
TextBox salary = (TextBox)gridview.Rows[e.RowIndex].Cells[8].FindControl("TextBoxEditSalary"); //salary
updateRow(itemID.Text, firstName.Text, lastName.Text, age.Text, eAddress.Text, department.ID, manager.ID, gender.Text, salary.Text); // call update method
gridview.EditIndex = -1; //Turn the Grid to read only mode
BindGrid(); // Rebind GridView to reflect changes made
Response.Write("Update Seccessful!");
}
Please help with code. Kindly help! Thanks.