Solved

Programatically Displaying image in gridview

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

756 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