Solved

Programatically Displaying image in gridview

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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 …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 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