Solved

DataBinding Expressions with conditions...

Posted on 2009-07-02
1
280 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
ID: 24769577
<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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

930 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

9 Experts available now in Live!

Get 1:1 Help Now