Skip to main content

ASP.NET Gridview and Conditioanl Image

Depending upon a value in the data source, we can conditionally display images in GridView columns. For example, the following TemplateField declaration conditionally displays approved.gif or unapproved.gif based on IsApproved flag in the DataSet that the GridView is bound to:
<asp:TemplateField HeaderText="Yes">
                       <ItemTemplate>
                         <asp:Image ID="ApprovalImage" Height="20px" Width="20px" runat="server" ImageUrl='<%# "~/Images/" + ((Eval("U_Yeah").ToString()== "Y") ? "apply.png" : "del.jpg") %>' />
                       </ItemTemplate>
 </asp:TemplateField>

Comments

Popular posts from this blog