---
title: "grid view bulk updating all cells"  
description: "grid view bulk updating all cells"  
author: "Pravesh Singh"  
published: 2014-08-25  
updated: 2014-08-25  
canonical: https://www.mindstick.com/forum/2128/grid-view-bulk-updating-all-cells  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# grid view bulk updating all cells

I am using a [asp.net](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) [grid view](https://www.mindstick.com/forum/477/grid-view) to load data from my sql data table.I am able to successfully load the data.

When user hits Edit button all the cells in the [gridview](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net) are made editable so that user can edit and save the values.

My [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) arises with the save button where i [am unable](https://answers.mindstick.com/qa/95314/how-do-i-access-a-group-link-in-telegram-if-i-am-unable-to-access-the-link) to save the edited data back to the SQL.

**Here is the code for the save [button click](https://www.mindstick.com/forum/790/form-gets-submiited-twice-on-button-click):**

```
protected void btnSave_Click(object sender, EventArgs e){    int RowIndex=0;    GridViewRow row = (GridViewRow)gvres.Rows[RowIndex];    TextBox txtLanguage1 = row.FindControl("txtFName") as TextBox;    TextBox txtLanguage2 = row.FindControl("txtLName") as TextBox;    SqlConnection myConnection = new SqlConnection(connectionString);    SqlCommand cmd = new SqlCommand("UPDATE UsersTable SET FirstName = @FirstName, LastName = @LastName WHERE Location = @Location", myConnection);    cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text.Trim());    cmd.Parameters.AddWithValue("@LastName", txtLastName.Text.Trim());    myConnection.Open();    cmd.ExecuteNonQuery();    gvusers.EditIndex = -1;    DataBind();}
```

[Exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling):"Must declare the scalar [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) "@[Location](https://www.mindstick.com/blog/11636/relocating-business-or-office-to-another-location)"."

## Replies

### Reply by Sumit Kesarwani

Hi Pravesh, try this:\

```
protected void btnSave_Click(object sender, EventArgs e){    int RowIndex=0;    GridViewRow row =(GridViewRow)gvres.Rows[RowIndex];    TextBox txtLanguage1 = row.FindControl("txtFName") as TextBox;    TextBox txtLanguage2 = row.FindControl("txtLName") as TextBox;    TextBox txtLanguage3 = row.FindControl("txtLocation") as TextBox;    SqlConnection myConnection = new SqlConnection(connectionString);    SqlCommand cmd = new SqlCommand("UPDATE UsersTable SET FirstName = @FirstName, LastName =
@LastName WHERE Location = @Location", myConnection);cmd.Parameters.AddWithValue("@FirstName",
txtFirstName.Text.Trim());cmd.Parameters.AddWithValue("@LastName",
txtLastName.Text.Trim());cmd.Parameters.AddWithValue("@Location",
txtLocation.Text.Trim());myConnection.Open();cmd.ExecuteNonQuery();gvusers.EditIndex = -1;DataBind();}
```


---

Original Source: https://www.mindstick.com/forum/2128/grid-view-bulk-updating-all-cells

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
