Adjusting ItemTemplate to show non-empty fields during Databind

  • Thread starter Thread starter SteveB
  • Start date Start date
S

SteveB

I have an SQl db with 5 address fields. Address field 1 and 2 always
contain data. Fields 3 4 and 5 are sometimes null. I have a Repeater set
up to display the addresses. How do show a conditional statement within
the ItemTemplate that will only display address fields containing
data(no blank lines). Assume you are talking to a complete beginner.

Thanks
 
Thanks for the reply

I don't want the null fields taking up space on the page.
Right now if the field is null I have a gap between the fields
containing data and the last field that contains City and State.

example:

Joe Smith
111 Mockingbird Lane



Slapout AL 32222
 
OK, now almost clear. You didn't say what components you're using in
ItemTemplate. Whatever they are, in the code-behind, in ItemDataBound event,
check if a field is null. If it is, set css class for the component used for
rendering the field to a rule with display:none.

Eliyahu
 
Thanks again..

I was using the code like

<%# DataBinder.EvalContainer.DataItem, "ADDR_1" %>
<%# DataBinder.EvalContainer.DataItem, "ADDR_2" %>
<%# DataBinder.EvalContainer.DataItem, "ADDR_3" %>
<%# DataBinder.EvalContainer.DataItem, "ADDR_4" %>
<%# DataBinder.EvalContainer.DataItem, "ADDR_5" %>
<%# DataBinder.EvalContainer.DataItem, "ADDR_6" %>

on the ASP page.

What you are saying is to use a control like label and use logic in the
code behind page. Would label be the best control to use in this
situation?
 
Here is a sample of the code I am using

Web Form

<asp:Repeater id="Repeater1" runat="server"
DataSource="<%# nad_Data1 %>" EnableViewState="False">
<ItemTemplate>
<tr>
<td bgcolor="AntiqueWhite" align="left">
<asp:Label Runat=server ID="lblAddr1" Text =
'<%#Check_Labels("ADDR_1")%>'/>
</td>

Code Behind:

public string Check_Labels(string fieldname)
{
string buf = "";
int Count = Repeater1.Items.Count;
for(int i = 0; i <= Count;i++)
{
DataTable dt = tablename.Tables[0];
buf = dt.Rows[fieldname].ToString();
}

{
return buf;
}
When the field is null or empty I need to set the display style to none.
I need to see an example of how this can work.
 
Back
Top