phil301
asked on
Programatically Displaying image in gridview
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(ByV al 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
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(ByV
If e.Row.RowType = DataControlRowType.DataRow
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
You'll have to get a handle to the image control by using cell.FindControl(ImageCont rolName). Once you get that, you can set the ImageURL property. If you post your markup, I can give you the exact code snippet.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.