Solved

Programatically Displaying image in gridview

Posted on 2006-11-07
3
1,991 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
  • 2
3 Comments
 
LVL 9

Expert Comment

by:kraffay
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now