Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: Index Out of Bounds Error

Reply
Thread Tools

Re: Index Out of Bounds Error

 
 
=?Utf-8?B?ZHdlbndhQGNvbXBhbnlhYmMuY29t?=
Guest
Posts: n/a
 
      10-20-2004
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:3925DD6E-D977-4812-A350-...
> > 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

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: list index out of bounds 1 error wha??? rf Computer Support 3 07-27-2009 07:00 PM
Custom MembershipProvider Index out of bounds/machineKey Mark Olbert ASP .Net 1 01-25-2006 06:46 AM
Catching vector index out of bounds Biff C++ 4 01-31-2005 05:55 AM
Index out of bounds question Method Man C Programming 26 10-22-2004 06:08 PM
DataGrid1.DataKeys[e.Item.ItemIndex] array index out of bounds Joel Finkel ASP .Net Datagrid Control 1 09-04-2003 04:31 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57