Gridview rowupdating event not
For example, when clicking the Edit button in an editable Grid View, the record's values are read from the database and displayed in Text Boxes and other Web controls. Later, after the user makes her changes and clicks the Update button, the original values plus the new values are sent to the Business Logic Layer, and then down to the Data Access Layer. For the Update Product method, use the overload that accepts all of the product's data fields.The Data Access Layer must issue a SQL statement that will only update the record if the original values that the user started editing are identical to the values still in the database. Figure 2: For the Update or Delete to Succeed, the Original Values Must Be Equal to the Current Database Values (Click to view full-size image) There are various approaches to implementing optimistic concurrency (see Peter A. After completing the wizard, the Object Data Source's declarative markup should look like the following: property at this point, since this property indicates that the BLL method expects the old (or original) values to be passed in as well as the new values.Figure 1: When Two Users Simultaneously Update a Record There s Potential for One User s Changes to Overwrite the Other s (Click to view full-size image) Similarly, when two users are visiting a page, one user might be in the midst of updating a record when it is deleted by another user.Or, between when a user loads a page and when they click the Delete button, another user may have modified the contents of that record.Rather than extend our existing DAL's Table Adapters to use optimistic concurrency (which would necessitate changing the BLL to accommodate), let's instead create a new Typed Data Set named Business Logic Layer class that has the appropriate modifications to support the optimistic concurrency DAL. There are no additional input parameters for specifying the original values. First, since we want the Grid View to support editing and deleting, click the Enable Editing and Enable Deleting checkboxes from the Grid View's smart tag.Once this groundwork has been laid, we'll be ready to create the ASP. To create a new Typed Data Set, right-click on the . Delete, true)] public bool Delete Product (int original_product ID, string original_product Name, int? original_category ID, string original_quantity Per Unit, decimal? This is possible because the Data Table keeps track of the original and modified values for its Data Row(s). This will add a Command Field whose Bound Fields will render as Text Boxes, requiring the user to enter the appropriate category and supplier as ID numbers.To have this Table Adapter employ optimistic concurrency control, simply check the "Use optimistic concurrency" checkbox. To see why this is important, take a moment to visit our page in a browser.Figure 6: Enable Optimistic Concurrency Control by Checking the "Use optimistic concurrency" Check Box (Click to view full-size image) Lastly, indicate that the Table Adapter should use the data access patterns that both fill a Data Table and return a Data Table; also indicate that the DB direct methods should be created. As expected, the Grid View lists each product with an Edit and Delete button in the leftmost column.
This results in an to the corresponding Beverages category ID, and so on.
Figure 4: Specify the Data to Retrieve Using an Ad-Hoc SQL Statement (Click to view full-size image) On the following screen, enter the SQL query to use to retrieve the product information. Specifically, the Grid View's original values are assigned the values in the two-way databinding statements each time the data is bound to the Grid View.
Let's use the exact same SQL query used for the SELECT Product ID, Product Name, Supplier ID, Category ID, Quantity Per Unit, Unit Price, Units In Stock, Units On Order, Reorder Level, Discontinued, (SELECT Category Name FROM Categories WHERE Categories. Category ID) as Category Name, (SELECT Company Name FROM Suppliers WHERE Suppliers. Supplier ID) as Supplier Name FROM Products Table Adapter in the Original DAL (Click to view full-size image) Before moving onto the next screen, click the Advanced Options button. Therefore, it's essential that the required original values all are captured via two-way databinding and that they are provided in a convertible format.
For example, imagine that two users, Jisun and Sam, were both visiting a page in our application that allowed visitors to update and delete the products through a Grid View control.
Both click the Edit button in the Grid View around the same time.