P
Paul S
I'm using a detailsview with an objectdatasource. When I click Update to
save my edited record ItemUpdating gets called but e.NewValues.Count = 0.
What am I doing wrong?
The design is a dropdown ddlEvent where a date is selected. With taht as a
key the event to be edited is selected in the DetailsView
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
try
{
MatchCollection matches = new MatchCollection();
matches.FillWithEventsAfter(new DateTime(2009, 1, 1), 10);
this.ddlEvent.DataValueField = "MatchId";
this.ddlEvent.DataTextField = "DateOfEvent";
this.ddlEvent.DataSource = matches;
this.ddlEvent.DataBind();
this.BindDetailsView();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
/// <summary>
/// New date has been selected so refresh view
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlEvent_SelectedIndexChanged(object sender,
EventArgs e)
{
//Response.Write(this.ddlEvent.SelectedValue.ToString());
this.BindDetailsView();
}
private void BindDetailsView()
{
MatchCollection matches = new MatchCollection();
matches.Fill(int.Parse(this.ddlEvent.SelectedValue));
this.dvEvent.DataSource = matches;
this.dvEvent.DataBind();
this.dvEvent.DefaultMode = DetailsViewMode.ReadOnly;
}
protected void dvEvent_ModeChanged(object sender, EventArgs e)
{
}
protected void dvEvent_ModeChanging(object sender,
DetailsViewModeEventArgs e)
{
this.dvEvent.ChangeMode(e.NewMode);
this.BindDetailsView();
}
protected void dvEvent_ItemCommand(object sender,
DetailsViewCommandEventArgs e)
{
if (e.CommandName.Equals("edit",
StringComparison.InvariantCultureIgnoreCase))
{
}
if (e.CommandName.Equals("Cancel",
StringComparison.InvariantCultureIgnoreCase))
{
;
}
if (e.CommandName.Equals("New",
StringComparison.InvariantCultureIgnoreCase))
;
if (e.CommandName.Equals("update",
StringComparison.InvariantCultureIgnoreCase))
{
this.dvEvent.UpdateItem(true);
}
}
protected void dvEvent_ItemUpdating(object sender,
DetailsViewUpdateEventArgs e)
{
MatchCollection matches = new MatchCollection();
matches.Fill(int.Parse(this.ddlEvent.SelectedValue));
if (matches.Count < 1)
return;
MatchInfo mi = matches[0];
mi.Description = e.NewValues["Description"].ToString();
mi.CourseId = (int)e.NewValues["CourseId"];
// etc
try
{
matches.Update();
this.dvEvent.ChangeMode(DetailsViewMode.ReadOnly);
}
catch (Exception)
{
}
// error handling
}
Thanks
Paul S
save my edited record ItemUpdating gets called but e.NewValues.Count = 0.
What am I doing wrong?
The design is a dropdown ddlEvent where a date is selected. With taht as a
key the event to be edited is selected in the DetailsView
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
try
{
MatchCollection matches = new MatchCollection();
matches.FillWithEventsAfter(new DateTime(2009, 1, 1), 10);
this.ddlEvent.DataValueField = "MatchId";
this.ddlEvent.DataTextField = "DateOfEvent";
this.ddlEvent.DataSource = matches;
this.ddlEvent.DataBind();
this.BindDetailsView();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
/// <summary>
/// New date has been selected so refresh view
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlEvent_SelectedIndexChanged(object sender,
EventArgs e)
{
//Response.Write(this.ddlEvent.SelectedValue.ToString());
this.BindDetailsView();
}
private void BindDetailsView()
{
MatchCollection matches = new MatchCollection();
matches.Fill(int.Parse(this.ddlEvent.SelectedValue));
this.dvEvent.DataSource = matches;
this.dvEvent.DataBind();
this.dvEvent.DefaultMode = DetailsViewMode.ReadOnly;
}
protected void dvEvent_ModeChanged(object sender, EventArgs e)
{
}
protected void dvEvent_ModeChanging(object sender,
DetailsViewModeEventArgs e)
{
this.dvEvent.ChangeMode(e.NewMode);
this.BindDetailsView();
}
protected void dvEvent_ItemCommand(object sender,
DetailsViewCommandEventArgs e)
{
if (e.CommandName.Equals("edit",
StringComparison.InvariantCultureIgnoreCase))
{
}
if (e.CommandName.Equals("Cancel",
StringComparison.InvariantCultureIgnoreCase))
{
;
}
if (e.CommandName.Equals("New",
StringComparison.InvariantCultureIgnoreCase))
;
if (e.CommandName.Equals("update",
StringComparison.InvariantCultureIgnoreCase))
{
this.dvEvent.UpdateItem(true);
}
}
protected void dvEvent_ItemUpdating(object sender,
DetailsViewUpdateEventArgs e)
{
MatchCollection matches = new MatchCollection();
matches.Fill(int.Parse(this.ddlEvent.SelectedValue));
if (matches.Count < 1)
return;
MatchInfo mi = matches[0];
mi.Description = e.NewValues["Description"].ToString();
mi.CourseId = (int)e.NewValues["CourseId"];
// etc
try
{
matches.Update();
this.dvEvent.ChangeMode(DetailsViewMode.ReadOnly);
}
catch (Exception)
{
}
// error handling
}
Thanks
Paul S