• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 656
  • Last Modified:

Specified argument was out of the range of valid values. Parameter name: index

Hi,

Please kindly help me resolved this error,

Dim txtDescription As TextBox = DirectCast(e.Item.Cells(1).Controls(0),TextBox)
Specified argument was out of the range of valid values. Parameter name: index

Thanks.

Server Error in '/' Application.
--------------------------------------------------------------------------------
Specified argument was out of the range of valid values. Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index
Source Error:
Line 118:                            Sub manage_update( s As Object, e As DataGridCommandEventArgs)
Line 119:                                Dim key As String= DataGrid1.DataKeys.Item(DataGrid1.EditItemIndex)
Line 120:                                Dim txtDescription As TextBox = DirectCast(e.Item.Cells(1).Controls(0),TextBox)
Line 121:                                Dim ddlteam As DropDownList = DirectCast(e.Item.Cells(2).FindControl("DropDownList1"),DropDownList)
Line 122:                                Dim ddldesignation As DropDownList = DirectCast(e.Item.Cells(3).FindControl("DropDownList2"),DropDownList)
 

Source File: c:\inetpub\wwwroot\shiftview.aspx    Line: 120
0
lynnton
Asked:
lynnton
  • 4
  • 3
1 Solution
 
Type25Commented:
Change line 120 to:

Dim txtDescription As TextBox = DirectCast(e.Item.Cells(1).Controls(1),TextBox)
0
 
lynntonAuthor Commented:
Type25,

Sadly same error message.

Please let me know if you need more information and on which part.

Thanks.
0
 
lynntonAuthor Commented:
Type25,

I think i may have something.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Type25Commented:
I'm guessing here as i don't know what index relates to what...

could try:

Dim txtDescription As TextBox = DirectCast(e.Item.Cells(0).Controls(1),TextBox)

It will always be .Controls(1)    as opposed to Controls(0)

0
 
lynntonAuthor Commented:
Type25,

it was a typo error on the store procedure, unfortunately this new error came up, is it fine with you to help me ?

Thanks.



                        Sub Manage_ItemDataBound(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
                                SetDeletionAlert(e.Item)
                                If e.Item.ItemType = ListItemType.EditItem Then
                                Dim DDL1 as DropDownList = e.Item.FindControl("DropDownList1")
                                DDL1.DataSource=GenerateSourcestarttime().defaultview
                                DDL1.DataTextField="starttime"
                                DDL1.DataValueField="shiftid"
                                DDL1.Items.Insert(0, "Select")
                                DDL1.DataBind()

                                Dim lbl1 as Label = e.Item.FindControl("lblSelected1")
                                Dim strSelected1 = CStr(lbl1.Text)
                                Dim i1 As ListItem = DDL1.Items.FindByText(strSelected1)
                                If strSelected1 <> "" Then
                                DDL1.Items.FindByText(strSelected1).Selected=true
                                else
                                DDL1.Items.Insert(0, "Select")
                                end if
                                End If
                        End Sub






Server Error in '/' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 199:                                Dim i1 As ListItem = DDL1.Items.FindByText(strSelected1)
Line 200:                                If strSelected1 <> "" Then
Line 201:                                DDL1.Items.FindByText(strSelected1).Selected=true
Line 202:                                else
Line 203:                                DDL1.Items.Insert(0, "Select")
 

Source File: c:\inetpub\wwwroot\shiftview.aspx    Line: 201

Stack Trace:

0
 
Type25Commented:
Hmm...   DDL1.Items.FindByText(strSelected1).Selected=true      

strSelected1  cannot be found in the DDL1 List.

You might try:
DDL1.Items.FindByValue(strSelected1).Selected=true

?
0
 
lynntonAuthor Commented:
Type25,

Same thing, how can we troubleshoot ?

Thanks,
0
 
Maulik ModiCommented:
Can you try with following code:

Dim dv as DataView = GenerateSourcestarttime().defaultview

     If  dv.Rows.Count > 0
                 DDL1.DataSource=dv
                  DDL1.DataTextField="starttime"
                   DDL1.DataValueField="shiftid"
                   DDL1.DataBind()
                   DDL1.Items.Insert(0, "Select")

                   Dim lbl1 as Label = e.Item.FindControl("lblSelected1")
                   Dim strSelected1 = CStr(lbl1.Text)

                    If strSelected1 <> "" Then
                             DDL1.Items.FindByText(strSelected1).Selected=true
                    else
                            DDL1.Items(0).Selected = true
                    end if            
        End If

Cheers!!!
MaulikCE
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now