Home All Groups Group Topic Archive Search About
Author
7 Mar 2005 7:08 PM
Steve Delia via .NET 247
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.

Thanks in advance
--------------------------------
From: Steve Delia

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>4BusL5JNJkGm8kr2ZUyaYg==</Id>

Author
7 Mar 2005 11:39 PM
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.
Show quoteHide quote
>
>Thanks in advance
>--------------------------------
>From: Steve Delia
>
>-----------------------
>Posted by a user from .NET 247 (http://www.dotnet247.com/)
>
><Id>4BusL5JNJkGm8kr2ZUyaYg==</Id>
>.
>