Gridview update using footer template
Hi All,
I have a grid with checkbox, where users can select multiple rows and edit at the same time and save it to the DB. Now I have used a Footer Template with textbox in the gridview. So if I want to put similar data's for some particular rows at the same time in the grid, I select the multiple rows and try to put values in the footer template textbox and when I click on save, it saves successfully.
protected void AIGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
TextBox Name = (TextBox)GridView1.FooterRow.FindControl("txtFRName");
TextBox Designation = (TextBox)GridView1.FooterRow.FindControl("txtFRDesignation");
TextBox City = (TextBox)GridView1.FooterRow.FindControl("txtFRCity");
string Na = Name.Text;
string Des = Designation.Text;
string Cy = City.Text;
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
bool isChecked = row.Cells[0].Controls.OfType<CheckBox>().FirstOrDefault().Checked;
TextBox EmpID = (TextBox)row.Cells[1].FindControl("txtEmpID");
if (isChecked)
{
if (e.CommandName.Equals("MassSave"))
{
AppGridData.UpdateGridValues(EmpID.Text, Na, Des, Cy);
this.FillVendorGrid();
}
}
}
}
}
UPDATE QUERY:
"UPDATE [Test] SET [Name]='" + Name + "',[Designation]= '" + Designation + "', [City]= '" + City + "' WHERE EmpID='" + EmpID + "'";
Now here is the challenge, but even when I enter null values in the footer template textbox it has to save with the old values of the rows and not null values. I tried it and couldn't make it happen. Anyone pls help me with the code....