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