DataGrid control

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
 
S

Shiva

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
 

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

Top