• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1209
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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