Repeater - checking for null values

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

I am using a repeater to display my search results (see
snippet below). If the DataItem is null, I don't want to
display the hyperlink text (Open Survey). Can I do an
If..Then right in the aspx page to check for a null or
blank value? I would much rather do this in the code-
behind if possible.
....
<td><asp:HyperLink NavigateUrl='<%# Databinder.Eval
(Container.DataItem, "Survey") %>' Runat="server"
ID="hypSurvey">Open Survey</asp:HyperLink></td>
....

Thanks.
 
Jason,
You should/can do this in codebehind, hook into the ItemDataBound event of
the repeater, it'll fire for each <itemTemplate> you'll have access to
e.Item.DataItem which you can cast to a DataRowView (my guess is that's what
you need). At that point you can access your fields, like

HyperLink h = (HyperLink) e.item.FindControl("hypSurvey");
h.visible = false;

or something similar..

Karl
 
Back
Top