A
Arpan
The following code creates a DataSet (with only one column named
"EmployeeName") in the Page_Load sub & populates a DataList:
<script runat="server">
'Build the DataSource
Function CreateDataSource() As ICollection
Dim dTable As New DataTable()
Dim dRow As DataRow
dTable.Columns.Add(New DataColumn("EmployeeName",
GetType(String)))
Dim i As Integer
For i = 0 To 9
dRow = dTable.NewRow()
dRow(0) = "SomeName" & i.ToString()
dTable.Rows.Add(dRow)
Next i
Dim dView As New DataView(dTable)
Return dView
End Function
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
'Bind 'DataView' to the DataSource
dList.DataSource = CreateDataSource()
dList.DataBind()
End If
End Sub
</script>
The DataList code hasn't been shown here. As such, the above code works
fine & populates the DataList with items starting from "SomeName0" to
"SomeName9".
Note the second line in the For...Next loop which says
dRow(0) = "SomeName" & i.ToString()
Now if the above line is changed to
dRow(i) = "SomeName" & i.ToString()
then the following error gets generated:
System.IndexOutOfRangeException: Cannot find column 1.
pointing to the
dRow(i) = "SomeName" & i.ToString
line. What's causing this error?
Thanks,
Arpan
"EmployeeName") in the Page_Load sub & populates a DataList:
<script runat="server">
'Build the DataSource
Function CreateDataSource() As ICollection
Dim dTable As New DataTable()
Dim dRow As DataRow
dTable.Columns.Add(New DataColumn("EmployeeName",
GetType(String)))
Dim i As Integer
For i = 0 To 9
dRow = dTable.NewRow()
dRow(0) = "SomeName" & i.ToString()
dTable.Rows.Add(dRow)
Next i
Dim dView As New DataView(dTable)
Return dView
End Function
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
'Bind 'DataView' to the DataSource
dList.DataSource = CreateDataSource()
dList.DataBind()
End If
End Sub
</script>
The DataList code hasn't been shown here. As such, the above code works
fine & populates the DataList with items starting from "SomeName0" to
"SomeName9".
Note the second line in the For...Next loop which says
dRow(0) = "SomeName" & i.ToString()
Now if the above line is changed to
dRow(i) = "SomeName" & i.ToString()
then the following error gets generated:
System.IndexOutOfRangeException: Cannot find column 1.
pointing to the
dRow(i) = "SomeName" & i.ToString
line. What's causing this error?
Thanks,
Arpan