Q

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;
  Next

  // Perform the update.
  sqlDataAdapter1.Update(ds);
  // Reload the grid.
  DataGrid2.DataBind();
End If

This was first published in April 2004

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close