|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Modify rows in DataTableASP.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> 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----- modify the columns of each row.>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 > DataGrid, to show upcoming events form my club. If the >For example, I create a table that gets bound to a event is today, I want to alter the text to say "Today!" and change the color. > loop via old ASP, but am new to ASP.NET and want to learn >I figure that I can resort to the old "Response.Write" 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> >. >
Newbie Question on Web DataGrid Focus
Avoid adding a new record on refreshing the browser Underline a whole row for a particular row How to read Column0 from DataGrid Help needed with DataGrid Client-Side Scripting Row Span in a grid? Embedded DropDownList in column. Viewstate question Access a BoundColumn's value in Update, other than .Cells()? DataGrid & Form on Same Page Post Issue |
|||||||||||||||||||||||