Solved

reading newvalues

Posted on 2008-11-03
8
357 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
Technology Partners: 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!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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