DataGrid control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using a DataGrid to display data returned from a database.
I've got a template column which displays the results from several fields.
Within this template column I want to display certain fields but only if the
data in a particular field is not null, but I can't get it to work:

<itemtemplate>
....
<%# If Not IsDBNull(DataBinder.Eval(Container.DataItem, "EditedBy") Then
DataBinder.Eval(Container.DataItem, "EditedBy") & " " &
DataBinder.Eval(Container.DataItem, "DateEdited")
End If %>
</itemtemplate>

How should I do this?

Many thanks for any help.

Alan
 
Here is one option:

<ItemTemplate>
<%# IIf (IsDBNull(DataBinder.Eval(Container.DataItem, "EditedBy"), ' ',
DataBinder.Eval(Container.DataItem, "EditedBy") & " " &
DataBinder.Eval(Container.DataItem, "DateEdited")) %>
</ItemTemplate>

I'm using a DataGrid to display data returned from a database.
I've got a template column which displays the results from several fields.
Within this template column I want to display certain fields but only if the
data in a particular field is not null, but I can't get it to work:

<itemtemplate>
....
<%# If Not IsDBNull(DataBinder.Eval(Container.DataItem, "EditedBy") Then
DataBinder.Eval(Container.DataItem, "EditedBy") & " " &
DataBinder.Eval(Container.DataItem, "DateEdited")
End If %>
</itemtemplate>

How should I do this?

Many thanks for any help.

Alan
 
Back
Top