Solved

reading newvalues

Posted on 2008-11-03
8
356 Views
Last Modified: 2012-05-05
I have a gridview and I used the following code to read the new values when updating data

string test = e.NewValues[3].ToString();

i got the following error.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
0
Comment
Question by:Mr_Shaw
  • 4
  • 4
8 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 22867602
How many columns does your gridview contains ? Remember that an index starts at 0 and not at 1

Perhaps this solves the problem: string test = e.NewValues[2].ToString();
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22867619
if e.NewValues.Count >= 4 then
    string test = e.NewValues[3].ToString()
end if
0
 

Author Comment

by:Mr_Shaw
ID: 22867634
15 column of text, 1 hidden column and a edit/delet button/colum.

A screen shot is below.
gridview.bmp
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 53

Expert Comment

by:Dhaest
ID: 22867645
Did you try something like this:
e.NewValues["MyColumnName"].ToString()
0
 

Author Comment

by:Mr_Shaw
ID: 22867720
I tried

string test = e.NewValues["record_name"].ToString();

and got an error saying 'Object reference not set to an instance of an object.'

i ran a test to see how many columns the code thinks is present. I used

e.NewValues.Count

My result equaled 0

Therefore string test = e.NewValues[3].ToString() would never work. I am really stuck on this one!

0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 22867749
in what event are you trying to capture your newvalues ?

Creating Audit Functionality Using ASP.NET 2.0
http://www.codeproject.com/KB/applications/CreateAuditFunction.aspx
0
 

Author Comment

by:Mr_Shaw
ID: 22867758
GridViewUpdateEventArgs
0
 

Author Comment

by:Mr_Shaw
ID: 22868081
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 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