Conditional statement in ASP GRID

Posted on 2007-10-08
Last Modified: 2008-02-08
What is wrong with the statement to  show a Grid Column.  I am checking the value of ATTACHMENT_FILE column from database, and if this value is NULL then i want the column to display the value in column FILE_NAME_URL from the database.

<%# IIf(Eval("ATTACHMENT_FILE") = "",<%#Eval("FILE_NAME_URL")%>, <img src="Assets/<%#Eval("ATTACHMENT_FILE")%>) %>

   <asp:GridView ID="dgGrid" runat="server"  AutoGenerateColumns="False"  Width=100% CellPadding="4" ForeColor="#333333"   DataKeyNames="ID" PageSize="25" AllowPaging="True" >
                                        <asp:TemplateField HeaderText=" ">
                                            <TABLE width="100%">
                                                <TR><TD colspan="2" valign="top"><Strong><%#Eval("DEALS_NAME")%></Strong></TD></TR>
                                                <TD width="80%"><p class="InputDisplay"><%#Eval("DEALS_DETAILS")%></p></TD>
                                                <TD width="20%">
<%# IIf(Eval("ATTACHMENT_FILE") = "",<%#Eval("FILE_NAME_URL")%>, <img src="Assets/<%#Eval("ATTACHMENT_FILE")%>) %>
                                                </TR>                                                <TR><TD width="100%" colspan="2"><TABLE width="100%" class="InputDisplay"><TR><TD  align="left" width="20%">Vendor:&nbsp;<i><%#Eval("VENDOR_NAME")%></i></TD><TD align="left"  width="20%">List Price:&nbsp;<i>US$<%#Eval("LIST_PRICE")%></i></TD><TD  align="left" width="20%">Category:&nbsp;<i><%#Eval("DEAL_CATEGORY")%></i></TD><TD  align="left" width="20%"><a target="_blank" style="TEXT-DECORATION: none" href="NotifyCredits.aspx?ID=<%#Eval("ID")%>">Notify Friends & Earn Credits</a></TD><TD align="left" width="20%"><a target="_blank" style="TEXT-DECORATION: none" href="1-ClickAccess.aspx?id=<%#Eval("ID")%>">1-Click Access</a>&nbsp;&nbsp;&nbsp;<!--<a style="TEXT-DECORATION: none" href="DealsPreview.aspx?ID=<%# Eval("ID") %>&Option=2">more details</a>&nbsp;--></TD></TR></TABLE></TD></TR>
                                           <HeaderStyle CssClass="InputDisplay" HorizontalAlign="Left" VerticalAlign="Top" Width="15%" />

                                     <RowStyle Font-Names="Arial" Font-Size="Smaller" BackColor="#EFF3FB" />
                                    <AlternatingRowStyle  Font-Names="Arial" Font-Size="Smaller"  BackColor="#F7F7FF" />
                                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                    <EditRowStyle BackColor="#2461BF" />
                                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                                    <PagerStyle cssclass="tableLabel" ForeColor="Black" HorizontalAlign="Left" />
                                    <HeaderStyle cssclass="TableMain" Font-Bold="True" height=10px ForeColor="White" />
                             <PagerSettings NextPageText="Next Deals&amp;gt;" PreviousPageText="&amp;lt;Prev Deals" Mode="NextPrevious" />
Question by:TECH_NET
    LVL 27

    Expert Comment

    You should do this in the gridview's RowDataBound event in code behind not in the aspx file
    some examples on how to use this event

    Good luck

    Accepted Solution

    please close the ticket.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    779 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

    18 Experts available now in Live!

    Get 1:1 Help Now