I have been using CellValidating event to validate cells data that user enters in a grid. It was important that e.Row.DataBoundItem != null and represent my Entity.
For this reason I have been using
BaseGridView_UserAddedRow event
and BaseGridView_DefaultValuesNeeded
like this
For this reason I have been using
BaseGridView_UserAddedRow event
and BaseGridView_DefaultValuesNeeded
like this
/// <summary>
/// Set DataBoundItem when user is adding new row
/// </summary>
protected
override
void
BaseGridView_DefaultValuesNeeded(
object
sender, GridViewRowEventArgs e)
{
e.Row.DataBoundItem =
new
TEntity();
}
/// <summary>
/// Update Grid DataBountItem after saving. If don't do this, ((Entity)DataBoundItem).Id will be 0.
/// </summary>
private
void
BaseGridView_UserAddedRow(
object
sender, GridViewRowEventArgs e)
{
e.Row.DataBoundItem = Entity;
}