Modify rows in DataTable

Discussion in 'ASP .Net Datagrid Control' started by Elton Wang, Mar 7, 2005.

  1. Elton Wang

    Elton Wang Guest

    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.
    >
    >Thanks in advance
    >--------------------------------
    >From: Steve Delia
    >
    >-----------------------
    >Posted by a user from .NET 247 (http://www.dotnet247.com/)
    >
    ><Id>4BusL5JNJkGm8kr2ZUyaYg==</Id>
    >.
    >
    Elton Wang, Mar 7, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J. Babe
    Replies:
    1
    Views:
    8,313
    Kevin Spencer
    Aug 15, 2003
  2. Fredrik Rodin

    Sort a datatable and create a new datatable

    Fredrik Rodin, Feb 16, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    9,027
    paul.mariotti
    Sep 28, 2007
  3. =?Utf-8?B?Qmx1ZWZsb3dlcg==?=

    Casting DataTable to class inherit from DataTable

    =?Utf-8?B?Qmx1ZWZsb3dlcg==?=, Apr 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    987
    =?Utf-8?B?Qmx1ZWZsb3dlcg==?=
    Apr 2, 2004
  4. jg
    Replies:
    1
    Views:
    713
    =?Utf-8?B?U2hhaWxlc2ggSmFubnU=?=
    Aug 17, 2004
  5. Ersin Gençtürk
    Replies:
    1
    Views:
    3,463
    Ersin Gençtürk
    Oct 6, 2004
Loading...

Share This Page