Solved

DataBinding Expressions with conditions...

Posted on 2009-07-02
1
279 Views
Last Modified: 2012-05-07
Hi,

I have the following DataBinding Expressions:  "<%#Eval("LocationCity")%>", "<%#Eval("LocationState")%>" & "<%#Eval("LocationZip")%>".  How can I check if <%#Eval("LocationCity")%> is empty or blank?  In other words, I don' t want to show the comma (,) when <%#Eval("LocationCity")%> is empty.  I tried "<%#if(Eval("LocationCity") != null)%>", it didn't work.

Please help. Thanks.


<asp:DataList 

            ID="dlLocations" 

            CssClass="dataView" 

            AlternatingItemStyle-BackColor="#F2F9FF" 

            BorderStyle="Solid" 

            BorderWidth="1px" 

            GridLines="Horizontal" 

            HorizontalAlign="Left" 

            Runat="server">

            <ItemTemplate>

             <%#Eval("LocationName")%><br />

              <%#Eval("LocationCity")%>,  <%#Eval("LocationState")%> <%#Eval("LocationZip")%>

            </ItemTemplate>

        </asp:DataList>

Open in new window

0
Comment
Question by:WebAppDeveloper
1 Comment
 
LVL 9

Accepted Solution

by:
Rahul Goel earned 500 total points
Comment Utility
<asp:DataList
            ID="dlLocations"
            CssClass="dataView"
            AlternatingItemStyle-BackColor="#F2F9FF"
            BorderStyle="Solid"
            BorderWidth="1px"
            GridLines="Horizontal"
            HorizontalAlign="Left"
            Runat="server">
            <ItemTemplate>
             <%#Eval("LocationName")%><br />
              <asp:Label ID="locationCity" runat="server" Text="<%#Eval("LocationCity")%>, " /> <%#Eval("LocationState")%> <%#Eval("LocationZip")%>
            </ItemTemplate>
        </asp:DataList>

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)

    {

        if (e.Item.ItemType == ListItemType.Item ||

          e.Item.ItemType == ListItemType.AlternatingItem)

        {

            System.Data.DataRowView drv =

                (System.Data.DataRowView)(e.Item.DataItem);

            if (drv.Row["LocationCity"].ToString() == string.Empty)

                e.Item.FindControl("urcontrol").Visible = false;

        }

    }

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now