Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 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 May 27th, 2008, 11:30 AM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default Putting an image in a Datalist, dependent on WHERE

I have a table of information that I want to display in a Gridview or a Datalist; when the boolean column "MadeinUSA" is TRUE, I want to display a little .gif flag image in that row of the displayed Gridview or Datalist, instead of just text or a checked checkbox.

With my shaky ASP.NET knowledge, I'm guessing I should do something with a template, inserting the flag image into the list or repeater's template with the Visible property set to "False", and then in the code-behind do something like "If MadeinUSA=1 Visible=TRUE".

So, I have a vague idea of how to do it, but I'm not sure exactly how to structure the syntax to make this work.

Any help would be appreciated!

 
Old May 28th, 2008, 07:03 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I dont know, there might be an easy solution, but I have done this before in the following way...

I have used a GridView. In that I have added the column like this -
<asp:TemplateField HeaderText="IsActive">
    <ItemTemplate>
         <asp:Image runat="server" ImageUrl='<%#getIcon(Container.DataItem) %>'/>
    </ItemTemplate>
</asp:TemplateField>

In the code behind I have added the following function -
protected string getIcon(object DataItem)
    {
        int status = Int32.Parse(DataBinder.Eval(DataItem, "status").ToString());
        if (status == 0)
            return "images/active.gif";
        else
            return "images/suspend.gif";

    }

You can try out in this way. If anyone has any better solution please post that.
 
Old June 6th, 2008, 10:32 PM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default

I will try this -- thank you very much!

 
Old June 7th, 2008, 04:21 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

If it's just a matter of hiding or showing the image, then you could also bind to the Visible property directly:

<asp:Image runat="server" ImageUrl="MadeinUSA.gif" Visible='<%# Bind("MadeinUSA") %>' />

For more complex scenarios (e.g. determining the correct image), angshujit's solution is perfect.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old June 9th, 2008, 08:58 PM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 Hi there,

If it's just a matter of hiding or showing the image, then you could also bind to the Visible property directly:

<asp:Image runat="server" ImageUrl="MadeinUSA.gif" Visible='<%# Bind("MadeinUSA") %>' />

For more complex scenarios (e.g. determining the correct image), angshujit's solution is perfect.

Cheers,

Imar
Perfect. This never occured to me, and yet is so simple.

I'm saving a copy of angshujit's method as well, for when I inevitably have to choose between multiple icons.

Thank you both very much!






Similar Threads
Thread Thread Starter Forum Replies Last Post
dependent select menu hastikeyvan Classic ASP Professional 3 November 10th, 2006 01:46 PM
dependent drop downs p2pMember ASP.NET 1.0 and 1.1 Professional 0 July 19th, 2006 05:25 AM
dependent select menu hastikeyvan Dreamweaver (all versions) 1 February 27th, 2006 04:34 AM
Look up value dependent on 2 other variables nkrukovsky Excel VBA 1 September 22nd, 2004 09:51 PM
dependent dropdown lists vivshah VS.NET 2002/2003 1 March 29th, 2004 05:25 PM





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