Hi Gary,
Thank you for your update.
To perform v1-style databinding and editing using GridView, you need to
handle the ItemCommand event to capture the Edit command (just like you
handled the EditCommand event using DataGrid). You also need to re-databind
the GridView after changing the EditIndex in order to cause the grid to
re-render the data in edit mode. Same as DataGrid.
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs
e) {
if (e.CommandName == "Edit") {
GridView1.EditIndex = Int32.Parse(e.CommandArgument.ToString());
GridView1.DataSource = ObjectDataSource1;
GridView1.DataBind();
}
}
Also, you must handle many required events when setting DataSource at
runtime.
However, you could probably avoid all this work by simply making your
DataSource available through an ObjectDataSource control and then
databinding the GridView using DataSourceID instead of the v1-style
approach.
Since you mentioned you're using one GridView to update several
DataSources, I suppose you're still updating a DataSource at one time.
I suggest you to use one ObjectDataSource, but create the Select, Delete,
Update, Insert methods with one additional parameter to distinguish the
user's selection. When you declare the ObjectDataSource in ASPX, you can
use the <UpdateParameters>, <DeleteParameters>, etc. to include a
ControlParameter which references the control that represents user's
selection. In ObjectDataSource's methods, you will know which data source
is expected to access.
Hope this helps. Please feel free to post here if anything is unclear.
Regards,
Walter Wang (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.