hk308
asked on
How to extract an integer value from the NewValues property of DetailsViewUpdateEventArgs?
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[\"GoalsAgains t\"].ToStr ing() "
+ e.NewValues["GoalsAgainst" ].ToString ();
if (((Int32)(e.NewValues["Goa lsFor"]) < 0) || ((Int32)(e.NewValues["Goal sAgainst"] ) < 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["Goal sAgainst"] ), 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?
protected void DetailsView1_ItemUpdating(
{
lblMsg.Text = "e.NewValues[\"GoalsAgains
+ e.NewValues["GoalsAgainst"
if (((Int32)(e.NewValues["Goa
{
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"
The online help refers to the "Dictionary" interface, which confuses me more than it helps. What am I missing here?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.