ASP.Net question concerning ItemTemplate in a GridView

J

Jay

I use many GridView controls bound to data sources on an
ASP.Net Web site.

One of my controls shows address information
as follows:

MyName
MyAddress1
MyAddress2
MyCity, MyState MyZIP

The above information are incorporated into an
ItemTemplate with the fields evaluated at run time
with HTML <br /> tags after each field except the
last.

If MyAddress2 contains no data, then I want
the city, state and ZIP to be on the next
line following MyAddress1.

How do I "inform" the template not to
leave a blank line if MyAddress2 is null?
 
A

Alberto Poblacion

Jay said:
[...]
How do I "inform" the template not to
leave a blank line if MyAddress2 is null?

The databinding syntax in the template allows you to enter any
expression that can be evaluated, so you may enter something like <%#
string.IsNullOrEmpty(Eval("MyAddress2"))?"":Eval("MyAddress2")+"<br />" %>
 
J

Jay

[...]
How do I "inform" the template not to
leave a blank line if MyAddress2 is null?

    The databinding syntax in the template allows you to enter any
expression that can be evaluated, so you may enter something like <%#
string.IsNullOrEmpty(Eval("MyAddress2"))?"":Eval("MyAddress2")+"<br />" %>

Right on. Thanks.

I would add one thing: the argument of string.IsNullOrEmpty ( ) must
be
a string, and so write

string.IsNullOrEmpty(Eval("MyAddress2").ToString() )? "" : Eval
("MyAddress2") + "<br />" %>

and this produces exactly what I wanted.

Now, I need to add another
feature. Where the listed institution has multiple locations, such as
a business
chain, I need to collapse all of the listings to a single line which
lists
MyBigBusinessChain which can be expanded by the user to expose all
of the local locations. Probably will fold an AJAX CollapsiblePanel
control
into a grid view, but I'll make that the subject of another post in
a related newsgroup.

Again, AP, thanks.

J
 

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