How to extract an integer value from the NewValues property of DetailsViewUpdateEventArgs?
Posted on 2006-04-07
I have a DetailsView control with Edit, Delete and New buttons. After editing the data in the view, and before updating, I need to validate user input, so I have a DetailsView_ItemUpdating method:
protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
lblMsg.Text = "e.NewValues[\"GoalsAgainst\"].ToString() "
if (((Int32)(e.NewValues["GoalsFor"]) < 0) || ((Int32)(e.NewValues["GoalsAgainst"]) < 0))
lblMsg.Text = "Cannot have a negative score";
e.Cancel = true;
I know that, for example, the data in the "GoalsAgainst" field is a finite integer, because the e.NewValues["GoalsAgainst"].ToString() returns "6". When I try the cast ((Int32)(e.NewValues["GoalsAgainst"]), however, I get an invalid cast exception, with the additional information that "... When casting from a number, the value must be a number less than infinity."
The online help refers to the "Dictionary" interface, which confuses me more than it helps. What am I missing here?