Archive

Archive for November 23, 2010

Manually Databinding a GridView

November 23, 2010 Leave a comment

Posted by: Aaron Goldenthal 4/19/2009 9:36 PM

One of the questions I see frequently on the ASP.NET forums is how to deal with exceptions like

The GridView ‘GridView1′ fired event RowEditing which wasn’t handled.

The GridView ‘GridView1′ fired event PageIndexChanging which wasn’t handled.

The GridView ‘GridView1′ fired event Sorting which wasn’t handled.

The GridView ‘GridView1′ fired event RowDeleting which wasn’t handled.

when manually databinding a GridView.  When I say manually databinding I mean not using a data source control specified as a DataSourceID, but rather setting the GridView’s DataSource equal to the appropriate data object and calling DataBind.  Developers who were around before ASP.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 DataSourceID, which buys you a lot of automation that you may not even appreciate unless you’ve done this the old fashioned way.  In this example, we’ll go through a fully featured GridView with editing, deleting, selecting, sorting, and paging functionality that is manually bound and identify the limitations and some of the workarounds.

When you use a data source control (e.g. SqlDataSource, ObjectDataSource, LinqDataSource, etc) specified in a DataSourceID, the GridView can automate many functions because, through the data source control, the GridView on its own can perform the following operations:

  • Select data (required any time databinding is required)
  • Update data
  • Delete data
  • Insert data (not necessarily applicable for a GridView, but it is for other data controls) Read more…
Categories: ASP.net Tags:
Follow

Get every new post delivered to your Inbox.