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