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. button in gridview's header not fired event

button in gridview's header not fired event

Scheduled Pinned Locked Moved ASP.NET
helpdesign
11 Posts 3 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.
  • M Mhiny

    I have a gridview that autogeneratecolumns is true.I want to adding button to gridview's header .The problem is button not fired event. My code : Protected Sub grdPoint_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdPoint.RowDataBound If e.Row.RowType = DataControlRowType.Header Then For i As Integer = 9 To 20 Dim btn As New Button AddHandler btn.Click, AddressOf click btn.ID = i btn.Text = e.Row.Cells(i).Text btn.EnableViewState = True btn.CausesValidation = False e.Row.Cells(i).Controls.Add(btn) Next End If End Sub Public Sub click(ByVal sender As Object, ByVal e As System.EventArgs) 'do something End Sub Please help....

    S Offline
    S Offline
    Sherin Iranimose
    wrote on last edited by
    #2

    where you are binding the grid view? Run time or design time?

    Copy and paste is a design error

    modified on Wednesday, July 2, 2008 3:41 AM

    M 1 Reply Last reply
    0
    • S Sherin Iranimose

      where you are binding the grid view? Run time or design time?

      Copy and paste is a design error

      modified on Wednesday, July 2, 2008 3:41 AM

      M Offline
      M Offline
      Mhiny
      wrote on last edited by
      #3

      Runtime.

      S 1 Reply Last reply
      0
      • M Mhiny

        I have a gridview that autogeneratecolumns is true.I want to adding button to gridview's header .The problem is button not fired event. My code : Protected Sub grdPoint_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdPoint.RowDataBound If e.Row.RowType = DataControlRowType.Header Then For i As Integer = 9 To 20 Dim btn As New Button AddHandler btn.Click, AddressOf click btn.ID = i btn.Text = e.Row.Cells(i).Text btn.EnableViewState = True btn.CausesValidation = False e.Row.Cells(i).Controls.Add(btn) Next End If End Sub Public Sub click(ByVal sender As Object, ByVal e As System.EventArgs) 'do something End Sub Please help....

        E Offline
        E Offline
        eyeseetee
        wrote on last edited by
        #4

        You have created an event called sub click but when does that get assigned to the button?

        We are not a Code Charity

        M 1 Reply Last reply
        0
        • E eyeseetee

          You have created an event called sub click but when does that get assigned to the button?

          We are not a Code Charity

          M Offline
          M Offline
          Mhiny
          wrote on last edited by
          #5

          I assigned at RowDatabound Event of gridview. Protected Sub grdPoint_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdPoint.RowDataBound If e.Row.RowType = DataControlRowType.Header Then For i As Integer = 9 To 20 Dim btn As New Button AddHandler btn.Click, AddressOf click btn.ID = i btn.Text = e.Row.Cells(i).Text btn.EnableViewState = True btn.CausesValidation = False e.Row.Cells(i).Controls.Add(btn) Next End If End Sub Is it wrong? I don't know where to assigned. Thank you all for answers

          E 1 Reply Last reply
          0
          • M Mhiny

            Runtime.

            S Offline
            S Offline
            Sherin Iranimose
            wrote on last edited by
            #6

            If you are filling the GridView at Page Load, inside if not ispostback block that is the problem. call the function outside the if block..

            Copy and paste is a design error

            M 1 Reply Last reply
            0
            • S Sherin Iranimose

              If you are filling the GridView at Page Load, inside if not ispostback block that is the problem. call the function outside the if block..

              Copy and paste is a design error

              M Offline
              M Offline
              Mhiny
              wrote on last edited by
              #7

              I'm sorry. I miss understand .I binding gridview at design time .I use gridview and objectdatasource . My gridview set autogeneratecolumns to true.Sorry I'm new to 2005 . Thank you for you reply

              S 1 Reply Last reply
              0
              • M Mhiny

                I assigned at RowDatabound Event of gridview. Protected Sub grdPoint_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdPoint.RowDataBound If e.Row.RowType = DataControlRowType.Header Then For i As Integer = 9 To 20 Dim btn As New Button AddHandler btn.Click, AddressOf click btn.ID = i btn.Text = e.Row.Cells(i).Text btn.EnableViewState = True btn.CausesValidation = False e.Row.Cells(i).Controls.Add(btn) Next End If End Sub Is it wrong? I don't know where to assigned. Thank you all for answers

                E Offline
                E Offline
                eyeseetee
                wrote on last edited by
                #8

                Well you have created the button at runtime in your row data bound event. But how does the button know which onclick event to use? Either you have done it wrong or I am confused as to what you have done. :) I think you need to add this when your button is created: btn.Click += new EventHandler(sub_Click); We are not a Code Charity

                S 1 Reply Last reply
                0
                • M Mhiny

                  I'm sorry. I miss understand .I binding gridview at design time .I use gridview and objectdatasource . My gridview set autogeneratecolumns to true.Sorry I'm new to 2005 . Thank you for you reply

                  S Offline
                  S Offline
                  Sherin Iranimose
                  wrote on last edited by
                  #9

                  Remove the coding from the RowDataBound and add following at page load and try For i As Integer = 2 To 19 Dim btn As New Button AddHandler btn.Click, AddressOf click btn.ID = i btn.Text = GridView1.HeaderRow.Cells(i).Text btn.EnableViewState = True btn.CausesValidation = False GridView1.HeaderRow.Cells(i).Controls.Add(btn) Next

                  Copy and paste is a design error

                  1 Reply Last reply
                  0
                  • E eyeseetee

                    Well you have created the button at runtime in your row data bound event. But how does the button know which onclick event to use? Either you have done it wrong or I am confused as to what you have done. :) I think you need to add this when your button is created: btn.Click += new EventHandler(sub_Click); We are not a Code Charity

                    S Offline
                    S Offline
                    Sherin Iranimose
                    wrote on last edited by
                    #10

                    No .netman, what he doing is right, It is VB.net way. The problem is, he is creating the button on the fly. So when he click on the button it will automatically erased, as HTTP is stateless.

                    Copy and paste is a design error

                    1 Reply Last reply
                    0
                    • M Mhiny

                      I have a gridview that autogeneratecolumns is true.I want to adding button to gridview's header .The problem is button not fired event. My code : Protected Sub grdPoint_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdPoint.RowDataBound If e.Row.RowType = DataControlRowType.Header Then For i As Integer = 9 To 20 Dim btn As New Button AddHandler btn.Click, AddressOf click btn.ID = i btn.Text = e.Row.Cells(i).Text btn.EnableViewState = True btn.CausesValidation = False e.Row.Cells(i).Controls.Add(btn) Next End If End Sub Public Sub click(ByVal sender As Object, ByVal e As System.EventArgs) 'do something End Sub Please help....

                      M Offline
                      M Offline
                      Mhiny
                      wrote on last edited by
                      #11

                      Thank you for all help. I find 2 place to put the code to addhandler for button at gridview's header. first at Pageload don't use if not page ispostback second at RowCreated this 2 place have same result .I don't know the best place to put this code but my code is complete .Thank you again to all :-D

                      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