Modify rows in DataTable

E

Elton Wang

Hi Steve,

Suppose you want to change text in some column depending
on the data in data source, you can do it in ItemDataBound
event.

Dim itemType As ListItemType = e.Item.ItemType
If itemType = ListItemType.AlternatingItem OrElse itemType
= ListItemType.Item Then
' Get data from underlying data source
Dim drv As DataRowView = CType(e.Item.DataItem,
DataRowView)
Dim cell As TableCell = e.Item.Cells(colIndex)
If drv(colindex) = (today's event) Then
cell.Text = "Today"
cell.BackColor = Color.Red
End If
End If

The ItemDataBound will automatically loop thru whole rows

HTH

Elton Wang
elton_wang_hotmail.com
-----Original Message-----
ASP.NET 1.1, Web Forms :
In my code I create a DataSet, then a DataTable within it.
I want to loop through the rows of the DataTable and
modify the columns of each row.
For example, I create a table that gets bound to a
DataGrid, to show upcoming events form my club. If the
event is today, I want to alter the text to say "Today!"
and change the color.
I figure that I can resort to the old "Response.Write"
loop via old ASP, but am new to ASP.NET and want to learn
the "right" way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top