Problem solve Get help with specific problems with your technologies, process and projects.

Make a datagrid update changes from all DB rows by clicking an update button

I am working on an ASP/VB.NET project. I have a datagrid that is pulling data from a SQL Server 2000 database. I have made most of the cells textboxes. I need to have the datagrid update all the changes from all rows to my database by clicking on an update button. The built-in edit function where you can only edit one row at a time does not help us. How can I do this? I read the answer you wrote asked on 21 July 2003 and it seems to help a little, but the answer is in C#. I need to know how to do this in VB.) Thank you for your time.
The solution is similar to that one. You have to iterate the grid rows and update the Dataset accordingly. The C# code I showed for that, would be in VB:
If (Page.IsValid)
  Dim ds As DataSet = CType(Session["data"], DataSet)
  Dim item As DataGridItem

  //Iterate and apply changes to the dataset
  For Each item In DataGrid2.Items
    Dim mytxt As TextBox = CType(TextBox, item.FindControl("myTxtBox"))
    // We may want to check if something has actually changed here...
    ds.Tables(0).Rows(item.ItemIndex)("myfield") = mytxt.Text;

  // Perform the update.
  // Reload the grid.
End If

Dig Deeper on .NET Framework database programming best practices

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.