M
Mythran
I have seen many examples on the Internet that do the following to format
data being bound to a DataGrid....IMO, it's sick..
Public Sub MyGrid_ItemDataBound( ... )
Dim value As String = e.Item.Cells(0).Text.ToLower()
If value = "true"
e.Item.Cells(0).Text = "Yes"
Else
e.Item.Cells(0).Text = "No"
End If
End Sub
Why would people use this instead of accessing the data row directly?
Public Sub MyGrid_ItemDataBound( ... )
Dim value As Boolean = e.Item.DataItem.Row.MyBooleanValue
e.Item.Cells(0).Text = IIf(value, "Yes", "No")
End Sub
IMO, it's easier and safer than using the TEXT value of the cell to get at
the data ... am I safe in assuming this?
We actually created another DataGrid (derived from DataGrid) that goes even
further by adding methods to retreive the cell of the data grid for the item
being bound (GetItemCell(DataGridItem, ColumnHeaderText)) to get the cell,
rather than accessing the cell ordinally. May take longer because it loops
to find the column ordinal with the specific ColumnHeaderText, but on MOST
if not ALL DataGrids, there are only a few columns of data...so the loop is
insignificant.
Thanks,
Mythran
data being bound to a DataGrid....IMO, it's sick..
Public Sub MyGrid_ItemDataBound( ... )
Dim value As String = e.Item.Cells(0).Text.ToLower()
If value = "true"
e.Item.Cells(0).Text = "Yes"
Else
e.Item.Cells(0).Text = "No"
End If
End Sub
Why would people use this instead of accessing the data row directly?
Public Sub MyGrid_ItemDataBound( ... )
Dim value As Boolean = e.Item.DataItem.Row.MyBooleanValue
e.Item.Cells(0).Text = IIf(value, "Yes", "No")
End Sub
IMO, it's easier and safer than using the TEXT value of the cell to get at
the data ... am I safe in assuming this?
We actually created another DataGrid (derived from DataGrid) that goes even
further by adding methods to retreive the cell of the data grid for the item
being bound (GetItemCell(DataGridItem, ColumnHeaderText)) to get the cell,
rather than accessing the cell ordinally. May take longer because it loops
to find the column ordinal with the specific ColumnHeaderText, but on MOST
if not ALL DataGrids, there are only a few columns of data...so the loop is
insignificant.
Thanks,
Mythran