Link to home
Start Free TrialLog in
Avatar of hk308
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[\"GoalsAgainst\"].ToString() "
                    + 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?
ASKER CERTIFIED SOLUTION
Avatar of gbzhhu
gbzhhu
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial