1) I noticed that if we don’t bind GridView to object data source control, then when user puts GridView into edit mode, we have to handle GridView.RowEditing event (else we 开发者_开发技巧get an exception ) and in this event put GridView’s row into editing mode. Is there a reason why GridView doesn’t automatically put a row into edit mode?
2) When we manually bind GridView to one of DataSet’s tables and user puts a row into edit mode, row’s columns will replace fields with text boxes. But for some reason these text boxes don’t display current field values, but instead they don’t display any text at all. What am I doing wrong?
3) I’ve also handled gridView.RowUpdated event, so I could put row back into non-edit mode, but to no effect. I even tried by pressing Edit button of some other row, but row still wouldn’t go out of edit mode. Any ideas what I’m doing wrong?
protected void gvwEmployees_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
e.KeepInEditMode = false;
}
Thanx
When not using a DataSource
control with a GridView
or other data-bound control which hide the complexity of the manual data-binding you must manually handle RowEditing
, RowUpdating
, and RowDeleting
etc. With the built in data model and automatic binding the GridView
handles these events for you.
You haven't posted your RowEditing
code, but i suspect that you are not setting the GridViews EditIndex
to the NewEditIndex
and are not rebinding, this is probably why you are not seeing current data.
protected void gvwEmployees_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView.EditIndex = e.NewEditINdex;
BindData();
}
The same is true for your RowUpdating
event. You will have to manually update your data, then set the EditIndex
to -1, this will put your GridView
back into ReadOnly
mode. Keep in mind that e.OldValues
, e.NewValues
and e.Keys properties of the GridViewUpdateEventArgs
are not populated when binding manually. This mean you'll have to take care of the update yourself by using e.RowIndex
which is the index of the edited row.
protected void gvwEmployees_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridView.EditIndex = -1;
BindData();
}
精彩评论