Link to home
Create AccountLog in
Avatar of TECH_NET
TECH_NET

asked on

Conditional statement in ASP GRID

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" >
                                    <Columns>
                                   
                                        <asp:TemplateField HeaderText=" ">
                                            <ItemTemplate>
                                            <TABLE width="100%">
                                                <TR><TD colspan="2" valign="top"><Strong><%#Eval("DEALS_NAME")%></Strong></TD></TR>
                                                <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")%>) %>
"/></TD>
                                                </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>
                                               </TABLE>
                                             
                                            </ItemTemplate>
                                           <HeaderStyle CssClass="InputDisplay" HorizontalAlign="Left" VerticalAlign="Top" Width="15%" />
                                        </asp:TemplateField>
                                     
                                       

                                    </Columns>
                                     <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" />
                                </asp:GridView>
Avatar of Sammy
Sammy
Flag of Canada image

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
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx
http://www.asp.net/learn/data-access/tutorial-11-vb.aspx

Good luck
ASKER CERTIFIED SOLUTION
Avatar of TECH_NET
TECH_NET

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer