Link to home
Start Free TrialLog in
Avatar of Mr_Shaw
Mr_Shaw

asked on

reading newvalues

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
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

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();
if e.NewValues.Count >= 4 then
    string test = e.NewValues[3].ToString()
end if
Avatar of Mr_Shaw
Mr_Shaw

ASKER

15 column of text, 1 hidden column and a edit/delet button/colum.

A screen shot is below.
gridview.bmp
Did you try something like this:
e.NewValues["MyColumnName"].ToString()
Avatar of Mr_Shaw

ASKER

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!

ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr_Shaw

ASKER

GridViewUpdateEventArgs