Solved

DataBinding Expressions with conditions...

Posted on 2009-07-02
1
281 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 ITIL 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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