473,387 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Index was out of range. Must be non-negative and less than the size of the collection Error

Pat
I have a 3 Datagrids.
The dtgMaster is the main datagrid and after selecting a ROW i populate the
second datagrid dtgDetails and the same for
the 3rd datagrid dtgChild.
But the thing is after clicking on a ROW on the dtgMaster and then select a
ROW in the second datagrid and the go back to the
dtgMaster which is the main datagrid and try to PAGE i get the error

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

At the line
Dim strFilter As String =
CStr(dtgDetails.DataKeys(dtgDetails.SelectedIndex) ).Replace("'", "''")
of the second DataGrid

Any ideas

Sub BindMaster()
Dim strQuery As String = "Select OrderID,InvoiceDate,OrderDate From
CMRC_Orders ORDER BY " & viewstate("sortField").ToString & " " &
viewstate("sortDirection").ToString

'Dim objConn As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))

Dim dataAdapter As New SqlDataAdapter(strQuery, objConn)
Dim ds As New DataSet

dataAdapter.Fill(ds)
dtgMaster.DataSource = ds
'dtgMaster.CurrentPageIndex = 0
dtgMaster.DataBind()

End Sub

Sub BindDetails()
' getting the filter value from the master Grid's DataKeys
collection

If dtgMaster.SelectedIndex <> -1 Then

Dim strFilter As String =
CStr(dtgMaster.DataKeys(dtgMaster.SelectedIndex)). Replace("'", "''")
Dim strQuery As String = "Select t1.OrderDetailID, t1.OrderID,
where t1.OrderID = '" & strFilter & "'"
Dim dataAdapter As New SqlCommand(strQuery, objConn)

objConn.Open()
dtgDetails.DataSource = dataAdapter.ExecuteReader()

End If
dtgDetails.DataBind()

End Sub


Sub BindChild()
If dtgDetails.SelectedIndex <> -1 Then
'Dim objConn As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))

'Error here
Dim strFilter As String =
CStr(dtgDetails.DataKeys(dtgDetails.SelectedIndex) ).Replace("'", "''")

'Dim strQuery As String = "Select t3.Feature from Orders where
t1.OrderDetailID= '" & strFilter & "'"

Dim dataAdapter As New SqlCommand(strQuery, objConn)
objConn.Open()

dtgChild.DataSource =
dataAdapter.ExecuteReader(CommandBehavior.CloseCon nection)

'Response.Write("<b>" & strFilter & "</b>")

End If
dtgChild.DataBind()
End Sub
Nov 19 '05 #1
0 7200

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: skura | last post by:
I am trying to understand how the data in sql server is stored and also regarding fill factor and page splitting. 1) My first question what is the difference between Index pages and Data pages....
4
by: DC | last post by:
When a nonunique nonclustered index is built on top of a clustered index, is it guaranteed that the bookmark in the nonclustered index will be kept in the same order as the clustered index? ...
14
by: Craig O'Shannessy | last post by:
Hi all, Just thought I'd mention that I really think this problem needs to be fixed. I I'm patching the 7.4RC1 JDBC drivers as we speak due to this optimiser bug, and it's the third time...
13
by: Chameleon | last post by:
I am programming in C++ for 4 years, so I am not a newbie but I am not a very experienced programmer on standard C++ libary. My question is this: Can you tell me one case which an iterator is...
15
by: rAinDeEr | last post by:
Suppose i have a table which holds thousands of records with the following structure CREATE TABLE "test "."T_CNTRY" ( "CNTRY_CDE" CHAR(2) NOT NULL , "CNTRY_NAME" VARCHAR(50) ) and i have...
14
by: micklee74 | last post by:
hi say i have string like this astring = 'abcd efgd 1234 fsdf gfds abcde 1234' if i want to find which postion is 1234, how can i achieve this...? i want to use index() but it only give me the...
35
by: erikwickstrom | last post by:
Hi all, I'm sorry about the newbie question, but I've been searching all afternoon and can't find the answer! I'm trying to get this bit of code to work without triggering the IndexError. ...
85
by: Russ | last post by:
Every Python programmer gets this message occasionally: IndexError: list index out of range The message tells you where the error occurred, but it doesn't tell you what the range and the...
0
by: muzu1232004 | last post by:
If I have a table t1 with a column a as follows A 1 1 1 1 1 1 1
1
by: Steffen Stellwag | last post by:
Truely is often better to scan a table in full passing by an index , but if you can force the optimizer to use an index via a hint for testing and comparing the results. But the index in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.