R
rn5a
A DataList has a Label control within the ItemTemplate &
AlternatingItemTemplate. The DataList is populated using a SQL query
wherein the 5th column is a column named 'Description'. The following
code resides in the OnItemDataBound event of the DataList:
Sub BindDataItem(ByVal obj As Object, ByVal ea As
DataListItemEventArgs)
Dim i As Integer
Dim dSet As DataSet
Dim dRow As DataRow
Dim sqlDapter As SqlDataAdapter
dSet = New DataSet
sqlDapter = New SqlDataAdapter
sqlDapter = ViewOrder(iUID, iOID)
sqlDapter.Fill(dSet)
If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
ListItemType.AlternatingItem) Then
For i = 0 To dSet.Tables(0).Rows.Count - 1
CType(ea.Item.FindControl("lbl1"), Label).Text =
dSet.Tables(0).Rows(i).Item(5).ToString
Next
End If
End Sub
Assume that the SQL query retrieves 3 records & the 3 records under the
5th column are "I am big", "I am bigger" & "I am biggest".
But the above code displays the record "I am biggest" in all the 3 rows
in the DataList. How do I make the DataList display "I am big" in the
first row, "I am bigger" in the second row & "I am biggest" in the
third row?
Please note that I could have easily accomplished this by setting the
Text property of the Label control to <%#
Container.DataItem("Description") %> in the DataList & binding the
DataList to the DataSet in the Page_Load sub but I did like to know how
to do the same in the OnItemDataBound event handler.
AlternatingItemTemplate. The DataList is populated using a SQL query
wherein the 5th column is a column named 'Description'. The following
code resides in the OnItemDataBound event of the DataList:
Sub BindDataItem(ByVal obj As Object, ByVal ea As
DataListItemEventArgs)
Dim i As Integer
Dim dSet As DataSet
Dim dRow As DataRow
Dim sqlDapter As SqlDataAdapter
dSet = New DataSet
sqlDapter = New SqlDataAdapter
sqlDapter = ViewOrder(iUID, iOID)
sqlDapter.Fill(dSet)
If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
ListItemType.AlternatingItem) Then
For i = 0 To dSet.Tables(0).Rows.Count - 1
CType(ea.Item.FindControl("lbl1"), Label).Text =
dSet.Tables(0).Rows(i).Item(5).ToString
Next
End If
End Sub
Assume that the SQL query retrieves 3 records & the 3 records under the
5th column are "I am big", "I am bigger" & "I am biggest".
But the above code displays the record "I am biggest" in all the 3 rows
in the DataList. How do I make the DataList display "I am big" in the
first row, "I am bigger" in the second row & "I am biggest" in the
third row?
Please note that I could have easily accomplished this by setting the
Text property of the Label control to <%#
Container.DataItem("Description") %> in the DataList & binding the
DataList to the DataSet in the Page_Load sub but I did like to know how
to do the same in the OnItemDataBound event handler.