• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1207
  • Last Modified:

Adding an image to multiple gridview headers

I'm attempting to add an image into the headers of specific columns in my gridview.  The code below doesn't throw an error but only adds the GIF to the final column referenced in the sub.  Can anyone offer any advice as to why that might happen??

Sub addImages(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
      If e.Row.RowType = DataControlRowType.Header Then
            Dim sortImage As New Image()
            sortImage.ImageUrl = "~/images/sorticon.gif"
            e.Row.Cells(1).Controls.Add(sortImage) ' <-- not added
            e.Row.Cells(2).Controls.Add(sortImage) ' <-- not added
            e.Row.Cells(3).Controls.Add(sortImage) ' <-- not added
            e.Row.Cells(4).Controls.Add(sortImage) ' <-- added!
      End If
End Sub
0
Rouchie
Asked:
Rouchie
1 Solution
 
lijunguoCommented:
That might happen because they will be using the same image id. But it's not allowed. You may try use four different image name, it should be working.

          Dim sortImage1 As New Image()
          sortImage1.ImageUrl = "~/images/sorticon.gif"
          Dim sortImage2 As New Image()
          sortImage2.ImageUrl = "~/images/sorticon.gif"
          Dim sortImage3 As New Image()
          sortImage3.ImageUrl = "~/images/sorticon.gif"
          Dim sortImage4 As New Image()
          sortImage4.ImageUrl = "~/images/sorticon.gif"
          e.Row.Cells(1).Controls.Add(sortImage1)
          e.Row.Cells(2).Controls.Add(sortImage2)
          e.Row.Cells(3).Controls.Add(sortImage3)
          e.Row.Cells(4).Controls.Add(sortImage4)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now