ArgumentOutOfRangeException for index

Posted on 2004-11-11
Last Modified: 2010-04-07
Specified argument was out of the range of valid values. Parameter name: index

Let me know if I'm following the right path here. OK, I'm updating a datagrid, so I need to obtain the values in the edit text boxes so I can then construct my UPDATE sql to update the record. Easy right. Well, using the following code I get the above mentioned error message:

 Dim FID As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
>Dim Fnd As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text

The .Cells(1). seems to work well but the program yaks on anything over 1.

Windows 2003, IIS 6, VB, Ole connection to Access database. Do you need to see anymore code?

I know that e.Item.Cells.Count = 7
when I add the value of i.Item.Cells(1).Controls(0) to a label I know it is the first bound column
the second bound column is sortable but read only - Is this the problem?
Question by:mfony
    LVL 6

    Accepted Solution

    LVL 20

    Expert Comment


    First off, do you have a condition which checking type of DataGridItem thats being process?

    If e.Item.ItemType = ListItemType.AlternatingItem And e.Item.ItemType = ListItemType.Item
       ' get the textbox control here..
    End If

    And are you sure you have a textbox in the cell index no. 2? If you know ID of the textbox before hand, why don't use e.FindControl method instead.

    Dim txt1 As TextBox = CType( e.FindControl( "theTextboxID" ), Textbox )
    Dim FIN As String = txt1.Text

    Featured Post

    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

    Join & Write a Comment

    Now that Expression Web 4.0 ( is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
    This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
    The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: :…
    The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

    734 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

    23 Experts available now in Live!

    Get 1:1 Help Now