Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Programatically Displaying image in gridview

Posted on 2006-11-07
3
Medium Priority
?
2,024 Views
Last Modified: 2008-01-09
I have a table that returns a column with 1 and 0. I wish to display a redx.gif if the column returns a 0, and a greencheck.gif if the column returns a 1.

I have determined I can use the rowdatabound to read the column value. Can someone tell me how I can add an imagefield column and assign it the proper gif per the returned result.
 Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound
           If e.Row.RowType = DataControlRowType.DataRow Then
            Dim cell As TableCell
            cell = e.Row.Cells(2)                              ("2 Is the column with the returned data")
            If CDbl(cell.Text) = 0 Then
               cell = e.Row.Cells(3)                            ("3 is the imagefield column")

"HOW DO I ASSIGN THE GIF IMAGES TO THE CELL HERE?"

               
            End If
        End If
    End Sub
0
Comment
Question by:phil301
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Expert Comment

by:kraffay
ID: 17893469
You'll have to get a handle to the image control by using cell.FindControl(ImageControlName).  Once you get that, you can set the ImageURL property.  If you post your markup, I can give you the exact code snippet.  
0
 
LVL 12

Accepted Solution

by:
craskin earned 1000 total points
ID: 17893966
for your example, by far the easiest solution would be to save 0.gif as a red x and 1.gif as your green check and then just add an imagefield control to the gridview with the datafield being that which returns the 1 or 0 and dataformatstring="{0}.gif"
0
 
LVL 12

Expert Comment

by:craskin
ID: 17893975
or you could even loop through your gridview and for every 0 it finds in that particular cell, it changes it to "redx.gif" and for every 1 to "greencheck.gif" or something like that. programmatically adding an image field just seems like a brute force method for something that's otherwise really simple.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question