?
Solved

DataBinding Expressions with conditions...

Posted on 2009-07-02
1
Medium Priority
?
285 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 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