Re: Index Out of Bounds Error

Discussion in 'ASP .Net' started by =?Utf-8?B?ZHdlbndhQGNvbXBhbnlhYmMuY29t?=, Oct 20, 2004.

  1. Ken,

    Thanks for the response. I found the problem. I didn't define a DataKey
    for the Datagrid. DataKeys are required to pick up the selected row. So my
    code looks like the following now:
    dvPromote = New DataView(dtPromote)
    dgRequests.DataSource = dvPromote
    dgRequests.DataKeyField = "Tran_ID"
    dgRequests.DataBind()
    I didn't show this code before, but the dgRequests.DataKeyField entry was
    missing.

    Thanks again for your help.

    Dave

    "Ken Cox [Microsoft MVP]" wrote:

    > Just wondering if your problem has to do with the For Each loop trying to
    > find a checkbox inside header and footer items?
    >
    > A fix would be to check that you are only looking inside
    > ListItemType.AlternatingItem and ListItemType.Item types
    >
    > Ken
    > MVP [ASP.NET]
    >
    >
    >
    > "" <>
    > wrote in message news:...
    > > Hi,
    > >
    > > I have a datagrid in my application that has a Template Column with a
    > > radiobutton. After selecting the item in the datagrid and the submit
    > > button,
    > > the program executes getSelectedItem(). See below. This works fine
    > > except
    > > when there is only one row in the datagrid. Then I get the Index out of
    > > bounds error.
    > >
    > > Has anyone seen this before?
    > >
    > > Dave
    > > Private Function GetSelectedItems(ByVal grdlst As DataGrid) As String
    > > Dim rowCount As Integer = 0
    > > Dim gridSelections As StringBuilder = New StringBuilder
    > > Try
    > > Dim oDataGridItem As DataGridItem
    > > For Each oDataGridItem In grdlst.Items
    > > Dim rdoSelected As RadioButton =
    > > CType(oDataGridItem.Cells(0).Controls(1), RadioButton)
    > >
    > > If rdoSelected.Checked = True Then
    > > rowCount += 1
    > > gridSelections.AppendFormat("{0}~",
    > > grdlst.DataKeys(oDataGridItem.ItemIndex).ToString())
    > > End If
    > > Next
    > >
    > > Catch ex As Exception
    > > lblMessage.Text = "Error finding selected row; " & ex.Message
    > > End Try
    > >
    > > If rowCount > 0 Then
    > > 'Remove the last separation symbol
    > > 'gridSelections.Remove(gridSelections.Length - 1, 1)
    > > Return (gridSelections.ToString)
    > > Else
    > > Return ("")
    > > End If
    > > End Function

    >
    >
    =?Utf-8?B?ZHdlbndhQGNvbXBhbnlhYmMuY29t?=, Oct 20, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    3,151
  2. Mark Olbert
    Replies:
    1
    Views:
    441
    Luke Zhang [MSFT]
    Jan 25, 2006
  3. Biff
    Replies:
    4
    Views:
    1,889
    E. Robert Tisdale
    Jan 31, 2005
  4. Method Man

    Index out of bounds question

    Method Man, Oct 14, 2004, in forum: C Programming
    Replies:
    26
    Views:
    633
    Dan Pop
    Oct 22, 2004
  5. Joel Finkel

    DataGrid1.DataKeys[e.Item.ItemIndex] array index out of bounds

    Joel Finkel, Sep 4, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    300
    Joel Finkel
    Sep 4, 2003
Loading...

Share This Page