Solved

reading newvalues

Posted on 2008-11-03
8
353 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
 
LVL 53

Expert Comment

by:Dhaest
ID: 22867645
Did you try something like this:
e.NewValues["MyColumnName"].ToString()
0
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

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

21 Experts available now in Live!

Get 1:1 Help Now