Rowupdating in gridview in vb net

24-Nov-2016 06:16 by 9 Comments

Rowupdating in gridview in vb net

We’re sorting on the appropriate field based on the Sort Expression, and setting the direction based on Sort Direction by calling either the Order By or Order By Descending methods. As with paging, we also reset the Edit Index and Selected Index when sorting.Finally we need to populate the Sort Expression and Sort Direction when they change, and we’ll handle that in the Sorting event. Also like paging, so show that it does get called, databinding is handled in the Sorted Event ( First, we obtain the User ID of the affected row from the Grid View Data Keys collection, which we use to pull the appropriate record from the database.

If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there.

In addition to that, we’re resetting the Edit Index and Selected Index when the page is changed to avoid cases, for example, where you change pages and are suddenly editing a different item.

Bind Data could be called in Page Index Changing, but to show that it the event is raised, we’ve handled that in Page Index Changed.

The important point is not which of these two events call Bind Data, but one of them must or the Grid View will not be updated. When bound using a Data Source ID, the Grid View internally tracks the current Sort Expression and Sort Direction, and those are available through properties with the same names.

When you manually bind the Grid View, this tracking does not occur, so we must implement some mechanism for tracking those values.

We’re using Linq to SQL to pull data from our database and bind it to the Grid View.

We’ll revisit this method when we implement the sorting functionality.

The Grid View does know the events that should be used to implement them, so the exceptions shown above are thrown when you try to perform one of these operations, but you have implemented the appropriate event handler.

The example shown here is for a Grid View, but the same types of event handlers must be implemented in roughly the same way for other data controls including the Form View, Details View, and List View. This is the final Grid View markup, so you can see the event handlers we’re going to implement.

We also need force databinding to occur when then page is loaded, which we’ll handle in Page_Load.

The required actions for paging to work are setting the new page index, setting the Data Source, and calling Data Bind (the last two through the Bind Data method).

After specifying the query, we add the appropriate sorting. When you bind a Grid View through a Data Source ID, the Grid View will update this value since it is internally tracking the sort expression, so it knows when to switch between ascending and descending.