Wednesday, March 21, 2012

Parameter name: index ERROR

Can some one please explain to me why I get the following error!
Thank you!
Exception Details: System.ArgumentOutOfRangeException: Specified argument wa
s out of the range of valid values. Parameter name: index
Source Error:
Line 156: 'Now, reference the LinkButton control that the Delete
ButtonColumn
Line 157: 'has been rendered to
Line 158: Dim deleteButton As LinkButton = e.Item.Cells(0).Contro
ls(0)
Line 159:
Line 160: 'We can now add the onclick event handler
..:: CODE ::..
Sub DGPages_Delete(ByVal sender As Object, ByVal e As DataGridCommandEventAr
gs)
'Get the ID of the row whose Delete button was clicked
Dim SelectedID As String = DGPages.DataKeys(e.Item.ItemIndex) ' Error
'Construct the Database Connection
Dim Myconn As New SqlConnection(ConfigurationSettings.AppSettings("strConn")
)
Dim cmd As New SqlCommand("PageDelete", Myconn)
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
' Add Parameters to the SQL query
Dim objID As SqlParameter
objID = cmd.Parameters.Add("@dotnet.itags.org.ID", SqlDbType.Int)
objID.Direction = ParameterDirection.Input
objID.Value = SelectedID
Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()
myReader.Close()
Myconn.Close()
BindData()
End Sub"Tim::.." <myatix_at_hotmail.com> wrote in message
news:5DDD0A8B-B41F-477F-BDC9-2BC8D6C5E583@.microsoft.com...
> Can some one please explain to me why I get the following error!
> Thank you!
> Exception Details: System.ArgumentOutOfRangeException: Specified argument
was out of the range of valid values. Parameter name: index
> Source Error:
> Line 156: 'Now, reference the LinkButton control that the
Delete ButtonColumn
> Line 157: 'has been rendered to
> Line 158: Dim deleteButton As LinkButton =
e.Item.Cells(0).Controls(0)
Either your item has no cells, or your cell has no child controls in it. To
find out which, remove the ".Controls(0)" and see what happens.
--
John Saunders
johnwsaundersiii at hotmail

0 comments:

Post a Comment