Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to know when mouse is clicked on gridview's column header.

how to know when mouse is clicked on gridview's column header.

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nettutorial
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    s_aslam98
    wrote on last edited by
    #1

    how to perform an action against the mouse click on the header of the c#asp.net gridview's column.

    S 1 Reply Last reply
    0
    • S s_aslam98

      how to perform an action against the mouse click on the header of the c#asp.net gridview's column.

      S Offline
      S Offline
      Sundar_R
      wrote on last edited by
      #2

      Simpler work around for this is var vTh = document.getElementsByTagName("th"); for(var i=0;i<vTh.length;i++) { vTh[i].onclick=yourmethod; } But make sure that your html doesn't contain anyother THs, if so add your own logic to restrict it inside the for loop.

      S 1 Reply Last reply
      0
      • S Sundar_R

        Simpler work around for this is var vTh = document.getElementsByTagName("th"); for(var i=0;i<vTh.length;i++) { vTh[i].onclick=yourmethod; } But make sure that your html doesn't contain anyother THs, if so add your own logic to restrict it inside the for loop.

        S Offline
        S Offline
        s_aslam98
        wrote on last edited by
        #3

        can u plz tel me how this code snippet is working.

        M S 2 Replies Last reply
        0
        • S s_aslam98

          can u plz tel me how this code snippet is working.

          M Offline
          M Offline
          mr_muskurahat
          wrote on last edited by
          #4

          in row databound event you will have to write something like.. if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onclick", "javascript:ChangeRowColor('" + e.Row.ClientID + "')"); } and changecolorfunction in javascript with what ever you want to do....

          umerumerumer

          1 Reply Last reply
          0
          • S s_aslam98

            can u plz tel me how this code snippet is working.

            S Offline
            S Offline
            Sundar_R
            wrote on last edited by
            #5

            Gridview column headers are nothing but THs in the html generated. In the body load you have to put that code which will loop through the list of Ths in the document and associate onclick event for all of them.

            S 1 Reply Last reply
            0
            • S Sundar_R

              Gridview column headers are nothing but THs in the html generated. In the body load you have to put that code which will loop through the list of Ths in the document and associate onclick event for all of them.

              S Offline
              S Offline
              s_aslam98
              wrote on last edited by
              #6

              but it is not recognizing 'var'

              S 1 Reply Last reply
              0
              • S s_aslam98

                but it is not recognizing 'var'

                S Offline
                S Offline
                Santhosh N
                wrote on last edited by
                #7

                This code needs to be registered on page load. TableObject.rows[0].onclick = Function("return YourFunctionName(this);"); Here TableObject is ur gridview object rows[0] gives the first row that is the header row. Then write ur logic in "YourFunctionName" Regards Santhosh N

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups