Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 14th, 2005, 06:16 AM
Authorized User
 
Join Date: May 2005
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Performing an IF test in a DataGrid

How do you perform an IF test in a DataGrid? Here is the code I'm trying so far:

<asp:TemplateColumn>
<ItemTemplate>
<% If Container.DataItem ("Prod_Image") <> 0 Then %>
<img src='assets/products/<%# Container.DataItem ("Prod_Image") %>' width='100' height='100'>
<% Else %>
&nbsp;
<% End If %>
</ItemTemplate>
</asp:TemplateColumn>

 
Old December 15th, 2005, 11:08 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The best way I've found to do things like this is to use a helper function in your codebehind that performs the final logic and call it from the markup template:

Protected Function CheckImage(intProdImage As Integer) As String
    If intProdImage <> 0 Then
        Return String.Format("<img src=""assets/products/{0}"" width=""100"" height=""100"">", intProdImage)
    Else
        Return "&nbsp;"
End If

<ItemTemplate><%# CheckImage(Container.DataItem("Prod_Image")) %></ItemTemplate>

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this right way for performing a slient install? SatheshKumar .NET Framework 1.x 0 August 4th, 2006 02:56 AM
Performing Division in XSLT... Please help.. kiril XSLT 3 May 17th, 2004 05:27 AM
Concurrency Violation performing Database updates LaFeverMF VB Databases Basics 1 February 15th, 2004 01:51 PM
Object or provider is not capable of performing re khalid08 Classic ASP Databases 1 September 22nd, 2003 03:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.