Home All Groups Group Topic Archive Search About
Author
7 Mar 2006 4:23 PM
rlrcstr
I'm using an ObjectDataSource with a GridView.  Is there an event, either in
the ObjectDataSource or teh GridView, that will let me intercept the
datasource before the GridView renders so that I can add a row?  I've tried
playing with the DataBinding and DataBoud events, but I can't seem to get
into the datasource in those events.

I'm trying to implement some AddNew functionality to the GridView and I
figured I could respond to a button click and add a blank row to the
datasource and throw it into edit mode immediately.  But how?

I've been searching for ways to implement add or insert functionality on the
GridView, but haven't found anything that was slick enough to rely on.
Thanks.

Jerry

Author
7 Mar 2006 5:40 PM
CaffieneRush@gmail.com
How about subclassing GridView and add your row within OnDataBound by
overriding the superclass' method.
This new row should contain the 'Insert' button that raises an insert
event.
Handle the insert event by writing you own OnRowInserting handler.
Author
8 Mar 2006 5:55 AM
Steven Cheng[MSFT]
Hi Jerry,

As for the Gridview control, it is template databound control , so its data
items(displayed) can not be added on the fly, the only means to add an
additional row is modify the underlying datasource bound to the GridView
control.  For the ObjectDataSource, it hasn't provided built-in interfaces
for adding additional rows to the underlying datasource(we can only perform
some filtering on the recordset). IMO, such modification should be done at
the DataAccess component class level, we can create a custom wrapper class
to encapsulate the original data access class(configured in
ObjectDataSource).  For example, we can create a custom wrapper class, its
data select method simply call the original data component's Select method
and do some additional customization on the returned datasource(add a row
or ...).

Please feel free to let me know if your have any other consideration or
idea.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)