Adjusting ItemTemplate to show non-empty fields during Databind

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
 
S

SteveB

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
 
E

Eliyahu Goldin

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
 
S

SteveB

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?
 
S

SteveB

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.
 

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

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top