【发布时间】:2016-08-31 20:40:57
【问题描述】:
我正在尝试检查是否在网格视图中选中了一个复选框,以及是否选中它以将其添加到数据表中。
但是,当未选中该行的复选框时,我收到一个错误:
位置 1 没有行。
这是我的代码:
'Creates a new datatable
Dim dtQuestions As New DataTable("QuestionsData")
'Add columns to datatable
For Each cell As TableCell In example.HeaderRow.Cells
dtQuestions.Columns.Add(cell.Text)
Next
For Each row As GridViewRow In example.Rows
Dim chkTest As CheckBox = CType(row.FindControl("chkTest"), CheckBox)
If chkTest.Checked = True Then
dtQuestions.Rows.Add()
For i As Integer = 0 To row.Cells.Count - 1
Try
dtQuestions.Rows(row.RowIndex)(i) = row.Cells(i).Text
Catch ex As Exception
End Try
Next
Else
'Do not add it to Datatable
End If
Next
我收到此代码的错误:
dtQuestions.Rows(row.RowIndex)(i) = row.Cells(i).Text
我不知道如何解决这个问题。
【问题讨论】: