Solved

Programatically Displaying image in gridview

Posted on 2006-11-07
3
2,003 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
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 250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 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