Adding an image to multiple gridview headers

Posted on 2006-06-07
Last Modified: 2011-09-20
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
Question by:Rouchie
    1 Comment
    LVL 11

    Accepted Solution

    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"

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now