how to get to the underlying data in a datagrid control?

Discussion in 'ASP .Net Datagrid Control' started by djc, Dec 16, 2004.

  1. djc

    djc Guest

    How do I get to the underlying data in a databound datagrid control? I have
    tried several different things all with no luck. I know you should be able
    to get to the data.... how exactly? The following is the last thing I tried
    and I get this error: "Name 'Container' is not declared". Another thing I
    tried is like below only I used e.DataItem instead of Container.DataItem and
    in that case I got an error indicating that 'DataItem' was not a valid
    property of 'e', or something to that effect.

    Sub OnItemDataBound_Handler(sender As Object, e As DataGridItemEventArgs)
    Dim itemType As ListItemType = e.Item.ItemType
    If itemType = ListItemType.Item Or itemType =
    ListItemType.AlternatingItem Then
    If Not DataBinder.Eval(Container.DataItem,
    "EstimatedDeliveryDate") Is DbNull.Value Then

    Dim TheETA As DateTime =
    DateValue(DataBinder.Eval(Container.DataItem("EstimatedDeliveryDate")))
    Dim TheStatus As String =
    DataBinder.Eval(Container.DataItem("Status")).ToString()

    If (TheETA < Today) And (TheStatus = "In Progress") Then
    e.Item.Cells(4).CssClass = "ETAColumnStyle_Overdue"
    End If

    End If
    End If
    End Sub

    any help would be greatly appreciated.
    thanks.
     
    djc, Dec 16, 2004
    #1
    1. Advertising

  2. djc

    Elton Wang Guest

    Following code snippet shows how to get data:

    DataRowView drv = (DataRowView)e.Item.DataItem;
    TableCell cell = (TableCell)e.Item.Controls[columnIndex];
    cell.Text = drv[columnIndex].Tostring().Substring(0,
    length);

    Dim drv As DataRowView = CType(e.Item.DataItem,
    DataRowView)
    Dim TheETA As DateTime = CType(drv
    ("EstimatedDeliveryDate"), DateTime)
    Dim TheStatus As String = drv("Status").ToString


    Elton Wang



    >-----Original Message-----
    >How do I get to the underlying data in a databound

    datagrid control? I have
    >tried several different things all with no luck. I know

    you should be able
    >to get to the data.... how exactly? The following is the

    last thing I tried
    >and I get this error: "Name 'Container' is not declared".

    Another thing I
    >tried is like below only I used e.DataItem instead of

    Container.DataItem and
    >in that case I got an error indicating that 'DataItem'

    was not a valid
    >property of 'e', or something to that effect.
    >
    >Sub OnItemDataBound_Handler(sender As Object, e As

    DataGridItemEventArgs)
    > Dim itemType As ListItemType = e.Item.ItemType
    > If itemType = ListItemType.Item Or itemType =
    >ListItemType.AlternatingItem Then
    > If Not DataBinder.Eval(Container.DataItem,
    >"EstimatedDeliveryDate") Is DbNull.Value Then
    >
    > Dim TheETA As DateTime =
    >DateValue(DataBinder.Eval(Container.DataItem

    ("EstimatedDeliveryDate")))
    > Dim TheStatus As String =
    >DataBinder.Eval(Container.DataItem("Status")).ToString()
    >
    > If (TheETA < Today) And (TheStatus = "In

    Progress") Then
    > e.Item.Cells(4).CssClass

    = "ETAColumnStyle_Overdue"
    > End If
    >
    > End If
    > End If
    > End Sub
    >
    >any help would be greatly appreciated.
    >thanks.
    >
    >
    >.
    >
     
    Elton Wang, Dec 17, 2004
    #2
    1. Advertising

  3. djc

    djc Guest

    THANK YOU THANK YOU THANK YOU!!!!!

    "Elton Wang" <> wrote in message
    news:102601c4e3cb$ed50fab0$...
    > Following code snippet shows how to get data:
    >
    > DataRowView drv = (DataRowView)e.Item.DataItem;
    > TableCell cell = (TableCell)e.Item.Controls[columnIndex];
    > cell.Text = drv[columnIndex].Tostring().Substring(0,
    > length);
    >
    > Dim drv As DataRowView = CType(e.Item.DataItem,
    > DataRowView)
    > Dim TheETA As DateTime = CType(drv
    > ("EstimatedDeliveryDate"), DateTime)
    > Dim TheStatus As String = drv("Status").ToString
    >
    >
    > Elton Wang
    >
    >
    >
    > >-----Original Message-----
    > >How do I get to the underlying data in a databound

    > datagrid control? I have
    > >tried several different things all with no luck. I know

    > you should be able
    > >to get to the data.... how exactly? The following is the

    > last thing I tried
    > >and I get this error: "Name 'Container' is not declared".

    > Another thing I
    > >tried is like below only I used e.DataItem instead of

    > Container.DataItem and
    > >in that case I got an error indicating that 'DataItem'

    > was not a valid
    > >property of 'e', or something to that effect.
    > >
    > >Sub OnItemDataBound_Handler(sender As Object, e As

    > DataGridItemEventArgs)
    > > Dim itemType As ListItemType = e.Item.ItemType
    > > If itemType = ListItemType.Item Or itemType =
    > >ListItemType.AlternatingItem Then
    > > If Not DataBinder.Eval(Container.DataItem,
    > >"EstimatedDeliveryDate") Is DbNull.Value Then
    > >
    > > Dim TheETA As DateTime =
    > >DateValue(DataBinder.Eval(Container.DataItem

    > ("EstimatedDeliveryDate")))
    > > Dim TheStatus As String =
    > >DataBinder.Eval(Container.DataItem("Status")).ToString()
    > >
    > > If (TheETA < Today) And (TheStatus = "In

    > Progress") Then
    > > e.Item.Cells(4).CssClass

    > = "ETAColumnStyle_Overdue"
    > > End If
    > >
    > > End If
    > > End If
    > > End Sub
    > >
    > >any help would be greatly appreciated.
    > >thanks.
    > >
    > >
    > >.
    > >
     
    djc, Dec 17, 2004
    #3
    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. =?Utf-8?B?RGljaw==?=

    ObjectDataSource's underlying data/schema

    =?Utf-8?B?RGljaw==?=, Mar 1, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,796
    Steven Cheng[MSFT]
    Mar 1, 2006
  2. velthuijsen
    Replies:
    2
    Views:
    354
    velthuijsen
    Nov 18, 2004
  3. ruksan
    Replies:
    1
    Views:
    452
    Karl Heinz Buchegger
    Mar 8, 2005
  4. Curious Trigger
    Replies:
    4
    Views:
    7,284
    Curious Trigger
    Jul 24, 2006
  5. placek
    Replies:
    6
    Views:
    218
Loading...

Share This Page