Solved

DataBinding Expressions with conditions...

Posted on 2009-07-02
1
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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