Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 27th, 2008, 11:30 AM
Authorized User
Points: 195, Level: 3
Points: 195, Level: 3 Points: 195, Level: 3 Points: 195, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , , .
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!

Reply With Quote
  #2 (permalink)  
Old May 28th, 2008, 07:03 AM
Authorized User
Points: 308, Level: 6
Points: 308, Level: 6 Points: 308, Level: 6 Points: 308, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2006
Location: Kolkata, West Bengal, India.
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.
Reply With Quote
  #3 (permalink)  
Old June 6th, 2008, 10:32 PM
Authorized User
Points: 195, Level: 3
Points: 195, Level: 3 Points: 195, Level: 3 Points: 195, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , , .
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default

I will try this -- thank you very much!

Reply With Quote
  #4 (permalink)  
Old June 7th, 2008, 04:21 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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.
Reply With Quote
  #5 (permalink)  
Old June 9th, 2008, 08:58 PM
Authorized User
Points: 195, Level: 3
Points: 195, Level: 3 Points: 195, Level: 3 Points: 195, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , , .
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!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:50 PM.


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