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

D

djc

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.
 
E

Elton Wang

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

(e-mail address removed)
 
D

djc

THANK YOU THANK YOU THANK YOU!!!!!

Elton Wang said:
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

(e-mail address removed)
-----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.


.
 

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,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top