Start Gridview onrowupdating event

Gridview onrowupdating event

We’ll start with binding data to the Grid View, then build up functionality from there.

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 assume that most of the employees that will be added in the future will be "Sales Representative". As the name of the User Adding Row implies, it allows for preventing the new row from being committed as a data row.

Moreover, the headquarters of the company is located in London, so most probably the new employees will have London as their city. This may be useful in case some of the data entered by the end-user is invalid according to some custom requirements.

As the name of the event implies, it allows you to set the default values for the new row which, if unchanged by the end-user, are saved in the row when the new row is committed by the end-user. In other cases, you may want to have a new record created immediately after the end-user starts editing the new row. The behavior of Rad Grid View in this situation is determined by the __Add New Bound Row Before Edit__property: Rad Grid View exposes several end-user events two of which you will find useful in the context of the new row: User Adding Row and User Added Row.

Let's have a Rad Grid View instance bound to the Employees table of the Northwind database. These events are fired when the user commits the new row (by pressing the Enter key or by clicking somewhere in the grid).

We’ll get to how these properties are populated shortly, but first we need to go back to the Bind Data method.

The original method shown above did not implement any sorting, but now that we have a place to store the Sort Expression and Sort Direction we need to change that.

Taking these assumptions into considerations, we will subscribe to the Default Values Needed event and will set the "Sales Representative" for the Title column and London for the City column: Private Sub Rad Grid View1_Default Values Needed(By Val sender As Object, By Val e As Telerik. In the examples below we will demonstrate what you can do by using the User Adding Row and User Added Row events.

User Adding Row Let's say that the Address column should allow no more than 30 characters per cell.

If the end-user types 40 characters in the Address cell of the new row and tries to commit this row, he will get a warning message box that the length of his input exceeds the allowed one, and the new row will not be committed. Grid View Row Cancel Event Args) Handles Rad Grid View1.