Solved

reading newvalues

Posted on 2008-11-03
8
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

718 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