M
MattB
Is there any way to reference a cell in a datagrid's ItemDataBound event by
it's DataItem column name (e.item.DataItem("colname")). I need to set a
cell's text to "" based on the contents of it's dataitem. I have this
working now by just referencing the cell's index (e.Item.Cells.Item(4)) but
I'm afraid of that breaking in the future if the columns get rearranged. So
can I derive the cell index from the DataItem? I couldn't come up with a way
that worked.
Here's what I'm currently doing:
Dim cell As TableCell
cell = e.Item.Cells.Item(4)
'hide the default date for non-date items
Dim dtStartDate As Date = e.Item.DataItem("start_date")
If dtStartDate.ToShortDateString = "1/1/0001" Then
cell.Text = ""
End If
-------------------------------------
So I'd really love to not have to specify 4 as my item and somehow derrive
that so if later that ends up being column 3 it won't break. Any ideas?
Thanks!
Matt
it's DataItem column name (e.item.DataItem("colname")). I need to set a
cell's text to "" based on the contents of it's dataitem. I have this
working now by just referencing the cell's index (e.Item.Cells.Item(4)) but
I'm afraid of that breaking in the future if the columns get rearranged. So
can I derive the cell index from the DataItem? I couldn't come up with a way
that worked.
Here's what I'm currently doing:
Dim cell As TableCell
cell = e.Item.Cells.Item(4)
'hide the default date for non-date items
Dim dtStartDate As Date = e.Item.DataItem("start_date")
If dtStartDate.ToShortDateString = "1/1/0001" Then
cell.Text = ""
End If
-------------------------------------
So I'd really love to not have to specify 4 as my item and somehow derrive
that so if later that ends up being column 3 it won't break. Any ideas?
Thanks!
Matt