Solved

GridView RowUpdating is not returning all items in the NewValues.Item array

Posted on 2007-11-28
7
1,471 Views
Last Modified: 2008-02-01
I have a gridview with about 15 or so columns, all of which are template fields. Most of the cells contain a single textbox, but some of them have multiple textboxes. During the gridview's RowUpdating event I am using e.NewValues.Item(n) to loop through all the values returned from the gridview. The problem is, I'm only receiving the values that are coming from the single-element cells, and I can't find the values from the textboxes in the multiple-element cells.

I'm receiving this error:

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

That tells me they're not even in the array. In the code below, the streets are all coming from the same cell, but they are being skipped (which I can tell when I print out the values in the lblTemp at the end).
Private Sub gvCompanies_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvCompanies.RowUpdating
    Dim intID As Integer = e.Keys(0)
    Dim strName As String = e.NewValues.Item(0)
    Dim strTicker As String = e.NewValues.Item(1)
    Dim strLocation As String = e.NewValues.Item(2)
    Dim strType As String = e.NewValues.Item(3)
    Dim strStreet1 As String = e.NewValues.Item(4)
    Dim strStreet2 As String = e.NewValues.Item(5)
    Dim strStreet3 As String = e.NewValues.Item(6)
    Dim strStreet4 As String = e.NewValues.Item(7)
    Dim strCity As String = e.NewValues.Item(8)
    Dim strState As String = e.NewValues.Item(9)
    Dim strZip As String = e.NewValues.Item(10)
    Dim strCountry As String = e.NewValues.Item(11)
    Dim strPhone As String = e.NewValues.Item(12)
    Dim strFax As String = e.NewValues.Item(13)
    Dim strClass As String = e.NewValues.Item(14)
    Dim strExecutives As String = e.NewValues.Item(15)
    Dim strIndustry1 As String = e.NewValues.Item(16)
    Dim ...
 
    lblTemp.Text = "ID = " & intID & _
    "<br />Name = " & strName & _
    "<br />Ticker = " & strTicker & _
    "<br />Location = " & strLocation & _
    "<br />Type = " & strType & _
    "<br />Street1 = " & strStreet1 & _
    "<br />Street2 = " & strStreet2 & _
    "<br />Street3 = " & strStreet3 & _
    "<br />Street4 = " & strStreet4 & _
    "<br />City = " & strCity & _
    "<br />State = " & strState & _
    "<br />Zip = " & strZip & _
    "<br />Country = " & strCountry & _
    "<br />Phone = " & strPhone & _
    "<br />Fax = " & strFax & _
    "<br />Class = " & strClass & _
    "<br />Executives = " & strExecutives & _
    "<br />Industry1 = " & strIndustry1
    ...
 
End Sub

Open in new window

0
Comment
Question by:CitySec
  • 3
  • 2
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20373522
How many elements in e.NewValues?  What is the type for each of the e.NewValues.Item(index)?

Bob
0
 
LVL 2

Author Comment

by:CitySec
ID: 20373760
There are 16 template field columns in my gridview, 3 of which have multiple textboxes, and 13 of which contain a single textbox.

There are 13 elements in e.NewValues, because it is throwing the error on e.NewValues(13) which is the 14th element. As for the types, they are all <asp:textbox> elements except State which is <asp:dropdownlist>.

Here are all the textboxes in the row that I need returned:

        Dim strName As String = e.NewValues.Item(0)
        Dim strTicker As String = e.NewValues.Item(1)
        Dim strLocation As String = e.NewValues.Item(2)
        Dim strType As String = e.NewValues.Item(3)
        Dim strStreet1 As String = e.NewValues.Item(4)
        Dim strStreet2 As String = e.NewValues.Item(5)
        Dim strStreet3 As String = e.NewValues.Item(6)
        Dim strStreet4 As String = e.NewValues.Item(7)
        Dim strCity As String = e.NewValues.Item(8)
        Dim strState As String = e.NewValues.Item(9)
        Dim strZip As String = e.NewValues.Item(10)
        Dim strCountry As String = e.NewValues.Item(11)
        Dim strPhone As String = e.NewValues.Item(12)
        Dim strFax As String = e.NewValues.Item(13)
        Dim strClass As String = e.NewValues.Item(14)
        Dim strExecutives As String = e.NewValues.Item(15)
        Dim strIndustry1 As String = e.NewValues.Item(16)
        Dim strIndustry2 As String = e.NewValues.Item(17)
        Dim strIndustry3 As String = e.NewValues.Item(18)
        Dim strIndustry4 As String = e.NewValues.Item(19)
        Dim strIndustry5 As String = e.NewValues.Item(20)
        Dim strIndustry6 As String = e.NewValues.Item(21)
        Dim strIndustry7 As String = e.NewValues.Item(22)
        Dim strIndustry8 As String = e.NewValues.Item(23)
        Dim strIndustry9 As String = e.NewValues.Item(24)
        Dim strIndustry10 As String = e.NewValues.Item(25)
        Dim strRevenue As String = e.NewValues.Item(26)
        Dim strEBITDA As String = e.NewValues.Item(27)
        Dim strDescription As String = e.NewValues.Item(28)

The Streets are all in the same cell, the Phone and Fax are in the same cell, and the Industries are all in the same cell.

Let me know if I'm not making this clear enough.

Brian
0
 
LVL 2

Accepted Solution

by:
CitySec earned 0 total points
ID: 20374238
I just noticed in the Gridview I'm using Eval instead of Bind on the values that are not being returned in the NewValues collection. Could this have something to do with it?
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 2

Author Comment

by:CitySec
ID: 20374313
Yeah, that was it. Sorry for the inconvenience, and thanks for taking the time to look at this for me!
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20374568
Good thing that you found it, because my crystal ball is in the shop getting fixed, and I wouldn't have known about Eval instead of Bind.   *BIG GRIN*

Bob
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20395574
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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…

809 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