DetailsViewInsertEventArgs.Values["xyz"] is null

  • Thread starter Thread starter Justin Dutoit
  • Start date Start date
J

Justin Dutoit

Hi folks. I've been learning about the DetailsView, and its Insert function.
I get a null reference from e.Values["whatever"].
My markup/code is below-

<asp:DetailsView runat="server" ID="basketdetails"
OnItemInserting="DoInsert"
DefaultMode="Insert" AutoGenerateRows="true"
AutoGenerateInsertButton="true"
DataKeyNames="BasketNumber"
HeaderStyle-CssClass="header"
RowStyle-CssClass="rowblue"
AlternatingRowStyle-CssClass="altrowblue">
</asp:DetailsView>

protected void DoInsert(object src, DetailsViewInsertEventArgs e)
{
info.Text = e.Values["CustomerNumber"].ToString() + " " +
e.Values["Total"].ToString() + " " +
e.Values["DateTimeBasketFinished"].ToString() + " " +
e.Values["Notes"].ToString() + ".";
}

All the key values (customernumber, total, datetimebasketfinished, notes)
exist in the data source for the detailsview. e.Values.Count equals zero.
I'd appreciate any help on why the Values are not being populated- perhaps
if someone can post some working code which I can emulate.

Thanks a lot!
Justin Dutoit
 
My experience (limited) was that you can only retrieve values for data
actually entered by the user. Set a breakpoint on that line of code and
examine the attributes of the event argument e. You can also check that
e.Exception == null && e.AffectedRows >= 1.
 
Back
Top