Rowupdating aspxgridview

The Grid View 'Grid View1' fired event Row Deleting which wasn't handled. When I say manually databinding I mean not using a data source control specified as a Data Source ID, but rather setting the Grid View’s Data Source equal to the appropriate data object and calling Data Bind. NET 2.0 are familiar with how to deal with this, but since ASP.

NET 2.0 most of the examples and tutorials deal with setting the Data Source ID, which buys you a lot of automation that you may not even appreciate unless you’ve done this the old fashioned way.

The way we’ll accomplish this is to create two properties that store those values in View State.

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

We can implement it in this way without a performance impact because the data is not actually retrieved from the database until required, so we can build up a chain of queries up to that point and only the end result will be pulled from the database. When manually databinding the Grid View, this will always show ascending, so we need to handle this manually with the following logic: After that we save the new Sort Expression.

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.

For the Bound Field, we don’t know the ID of the Text Box since it’s autogenerated by the Bound Field, so we obtain a reference to it by getting the first control in the appropriate cell in the edited row.

Since it’s a Bound Field, the Text Box is going to be Control[0].

But in the form, company combobox column is blank while it should be automatically selected. This grid has a detail grid which shows departments belonging to these companies. However, combobox shows wrong companies, usually the company which has the last ID.I chose one of the companies and departments which blongs to it appeared in the detail grid. Get Master Row Key Value(); doesn't match because Selected Index is object, Get Master Row Key Value is integer. 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.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.

Leave a Reply