Gridview rowupdating code
Fortunately Grid View can also be used without attaching with the Data Source Controls. In this article we will see how paging, sorting and editing can be implemented in a Grid View control that is bound with a Data View (or Data Table) directly.
This calls for some extra coding from developer's end. As an example we are going to use Employees table of the Northwind database. Add three Bound Fields and a Command Field to the Grid View with the help of Fields dialog (see below).
The method essentially binds the Grid View with a Data View.
The Data View supplies all the records from the Employees table.
The Sort Direction property specifies the direction of sorting i.e. This property is not of much when you are sorting the grid on your own.
However, when coupled with data source controls the Grid View can toggle the sorting direction automatically for you and you can get/set the direction using this property.
The Grid View Sort Event Args class has three important properties.
The Sort Expression property supplies the sort expression that you specified earlier for the column being sorted.
Binding form controls is mostly a simple matter of attaching a Data Source and setting your controls to reference the correct field in the Data Source. Binding a Grid View control can sometimes get tricky when using the Visual Studio editor, especially when working with Drop Down List controls within the grid. Today I was working on getting a row of the Grid View control to save the contents of a Drop Down List, and needed to add some custom code to set values passed to the Sql Data Source control on the update event. We set Page Index property of the Grid View to this new page number and call the Bind Grid() method again.
This will display the corresponding records in the Grid View.
I found that simple data binding of my Drop Down List in my Grid View to my Sql Data Source was not going to be enough.