473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Adjusting ItemTemplate to show non-empty fields during Databind


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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
6 1590
What do you want to hide when the fields are null?

Eliyahu

"SteveB" <no****@devdex.com> wrote in message
news:uV**************@TK2MSFTNGP10.phx.gbl...

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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
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

"SteveB" <no****@devdex.com> wrote in message
news:OV**************@TK2MSFTNGP11.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #4
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?




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #5
Yes, label should be fine.

Eliyahu

"SteveB" <no****@devdex.com> wrote in message
news:er**************@TK2MSFTNGP15.phx.gbl...
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?




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #6
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[i][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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ken Fine | last post by:
No joy on Macromedia's boards after a few days; maybe someone can help me here. I got an excellent string handling function off of planet-source-code.com that converts text strings to proper...
2
by: VB Programmer | last post by:
I have a datagrid with a dropdownlist in it. As I understand it, the ItemTemplate section represents the cell when not in edit mode and the EditItemTemplate section represents the cell when in...
2
by: Lerp | last post by:
Hi all, Is it possible to hide the itemtemplate when going into the edittemplate mode of a datalist? Cheers, Lerp
1
by: Jesper Pedersen | last post by:
Hi ! How do I access the following spillerID and Session from another *aspx page in my application? <ItemTemplate> <a href="player_details.aspx?spillerID=<%#...
3
by: webserverpete | last post by:
I would like to have multiple <td> in a repeater control. The below code does not work: <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" DataMember="DefaultView">...
4
by: Dabbler | last post by:
I need to convert a CompanyId in one table to Company Name from another table for an ItemTemplate. I thought I would just add another SqlDataSource but not sure how to eval with the CompanyId...
0
by: Gibs | last post by:
Hi, I am trying to create a repeater control anwith dynamic header and itemtemplate. In itemtemplate i do have to show the textboxes which i am going to create and want to retrieve the values in...
14
by: mistral | last post by:
Below is Typewriter Scroller script. I want adjust is as follows: remove lower dash "_" out; display text not in form, but inside div, without any borders (style="visibility:hidden"). Also I need...
0
by: sgtmarcjones | last post by:
How do I access a dropdownlist that is nested within a Formview ItemTemplate Gridview Template? I want to see a label (lgbTimeKeep ! TextValue of ddlName dropdownlist) instead of a dropdownlist...
7
by: JJ | last post by:
I'm sure this is quite simple, but clearly not for me today: How do you set the CSS Style of a tag in a repeater Item Template? e.g. I have this repeater: <asp:Repeater runat="server"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.