![]() |
Re: Index Out of Bounds Error
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] > > > > "dwenwa@companyabc.com" <dwenwacompanyabccom@discussions.microsoft.com> > wrote in message news:3925DD6E-D977-4812-A350-196F94772DF0@microsoft.com... > > 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 > > |
| All times are GMT. The time now is 05:27 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.