[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2006-04-07
Medium Priority
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

gbzhhu earned 375 total points
ID: 16402080
Have you tried using Convert.ToIn32  ?

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

834 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