Wednesday, June 1, 2011

ASP.NET GridView And Conditional Images

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="Approval Status"> 
<ItemTemplate> 
<asp:Image ID="ApprovalImage" runat="server" ImageUrl='<%# "~/Images/" + (((bool)Eval("IsApproved") == false) ? "Unapproved.gif" : "Approved.gif") %>' /> 
</ItemTemplate> 
<ItemStyle Width="25px" /> 
</asp:TemplateField> 

No comments:

Post a Comment

Ajax CalendarExtender displaying at wrong position in Chrome

< script type ="text/javascript" language ="javascript">     function onCalendarShown(sender, args)...