How to extract an integer value from the NewValues property of DetailsViewUpdateEventArgs?

Posted on 2006-04-07
Last Modified: 2012-05-05
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?
Question by:hk308
    1 Comment
    LVL 12

    Accepted Solution

    Have you tried using Convert.ToIn32  ?

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Problem with C# 1 44
    .Net Delete file in directory spaces in path 4 25
    C# Unrecognized Escape Sequence Error 5 28
    c# string 6 28
    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now