Gridview rowupdating not giving new values

05 Jan

When the end user clicks on an Edit button that row becomes editable, causing the Edit button to change to Update and Cancel buttons and the other columns to become Text Boxes.The end user can then update one or more column values and click Update to save their changes. Our first demo will look at how to create an editable Grid View whose data comes from a Sql Data Source.

gridview rowupdating not giving new values-74gridview rowupdating not giving new values-46gridview rowupdating not giving new values-60gridview rowupdating not giving new values-42

As we saw in the Deleting a Grid View's Underlying Data section, creating such a Sql Data Source is as simple as checking the Generate Insert, Update, and Delete Statements from the dialog box shown back in Figure 35.

(Recall that we created the Product DAL class back in the The Update Product Method (Visual Basic) Public Class Product DAL ... Close() End Using End Sub End Class The Update Product Method (C#) public class Product DAL As you can see, the Update method, Update Products(), takes in the original_Product ID along with each of the editable columns in the Grid View: product Name, unit Price, and units In Stock.

Public Shared Sub Update Product(By Val original_Product ID As Integer, _ By Val product Name As String, By Val unit Price As Decimal, _ By Val units In Stock As Integer) 'Updates the Products table Dim sql As String = "UPDATE Products SET Product Name = " & _ " @Product Name, Unit Price = @Unit Price, Units In Stock = " & _ "@Units In Stock WHERE Product ID = @Product ID" Using my Connection As _ New Sql Connection( _ Configuration Manager. Connection String) Dim my Command As New Sql Command(sql, my Connection) my Command. Add( _ New Sql Parameter("@Product Name", product Name)) my Command. Add(New Sql Parameter("@Unit Price", _ unit Price)) my Command. Add(New Sql Parameter("@Units In Stock", _ units In Stock)) my Command. Add(New Sql Parameter("@Product ID", _ original_Product ID)) my Connection. If you had configured the Object Data Source to Compare All Values you'd need an Update method with a signature like: ' Visual Basic .

The Grid View allows editing on a row-by-row basis.

An editable Grid View contains an additional column with an Edit button in each row.