473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DataRow

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.

Nov 20 '06 #1
1 1298
wouldn't you need to do something like:

ea.Item.FindControl("lbl" & i.ToString()) = XXX

and have a lbl0, lbl1 and lbl2 or something? You could dynamically add
them...

dim ph as placeHolder = ctype(ea.Item.FindControl("ph"), PlaceHolder)
for ...
dim l as new Label()
l.Text = dsSet.Tables(0)....
ph.Controls.Add(l)
next
On a side note, there's no point in calling ViewOrder and .Fill() unless the
itemType is Item or AlternatingItem (i.e., move all of your code INSIDE the
IF statement)...or write a guard clause:

if ea.Item.ItemType != Item AndAlso ea.Item.ItemType != AlternatingItem then
return
end if

Karl
--
http://www.openmymind.net/
http://www.codebetter.com/
<rn**@rediffmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
>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.
Nov 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Marcel Sottnik | last post by:
Hello group Maybe this is not the right NG, but this problem seems to me to be more language related than ADO.NET. How can I write the constructor for specialization of DataRow which will...
4
by: Michael Carr | last post by:
I have a function that populates a class with values from a database. I'd like to pass into the function either a SqlDataReader or a DataRow, depending on which mechanism I'm using to retrieve data...
2
by: Steve Amey | last post by:
Hi all I am binding a DataRow to some controls on a form. When I've finished editing the DataRow I click on a toolbar button to save the changes. If the focus is on a particular control, the...
6
by: JIM.H. | last post by:
Hello I have; DataRow dr= dataSet11.myTable.NewRow(); And I am filling the fields of this datarow. Now I need to create a copy of this row as drCopy and change a few fields and add both to...
1
by: Arpan | last post by:
This is how I am dynamically adding a table to a DataSet: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) 'Create an empty DataSet Dim dSet As New DataSet ...
5
by: samoore33 | last post by:
I use the code below to search through a DataSet: Dim t As DataTable t = result.Tables("State") Dim strExpr As String strExpr = "id = '" & theState.ToString() & "'" Dim foundRows() As DataRow...
10
by: mcbobin | last post by:
Hi, Here's hoping someone can help... I'm using a stored procedure to return a single row of data ie a DataRow e.g. public static DataRow GetManualDailySplits(string prmLocationID, string
5
by: Rainer Queck | last post by:
Hello NG, what would be the best way to locate a DataRrow in a DataGridView? I have by DataTable.Select a bunch of DataRows from a DataTable (which is the data source to the DataGridView). Now...
2
by: Ryan Liu | last post by:
Is DataRow uses DataRow and DataRow much efficient than DataRow? Thanks, ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. Ryan Liu Shanghai Fengpu Software Co. Ltd Shanghai , China
9
by: myotheraccount | last post by:
Hello, Is there a way to convert a DataRow to a StringArray, without looping through all of the items of the DataRow? Basically, I'm trying to get the results of a query and put them into a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.