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 can get the event of a button added in a datagrid in asp.net?

How can get the event of a button added in a datagrid in asp.net?

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminquestion
5 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
    SIJUTHOMASP
    wrote on last edited by
    #1

    Hai, I have added button using property builder in datagrid. I want to execute some functions under this button click.How I can get the server side events of that button.How I can do this? Please show me the right way. Thank You, Rahul.P.Menon.

    S M N 3 Replies Last reply
    0
    • S SIJUTHOMASP

      Hai, I have added button using property builder in datagrid. I want to execute some functions under this button click.How I can get the server side events of that button.How I can do this? Please show me the right way. Thank You, Rahul.P.Menon.

      S Offline
      S Offline
      sathish s
      wrote on last edited by
      #2

      a. use ItemDataBound_DataGrid Event b. find the control Dim btn AS Button = CType(e.Item.FindControl("Buttonname"),Button) C. add your event

      S 1 Reply Last reply
      0
      • S sathish s

        a. use ItemDataBound_DataGrid Event b. find the control Dim btn AS Button = CType(e.Item.FindControl("Buttonname"),Button) C. add your event

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

        Hai Satheesh, Thanks much for your reply. Rahul.P.Menon

        1 Reply Last reply
        0
        • S SIJUTHOMASP

          Hai, I have added button using property builder in datagrid. I want to execute some functions under this button click.How I can get the server side events of that button.How I can do this? Please show me the right way. Thank You, Rahul.P.Menon.

          M Offline
          M Offline
          Mike Ellison
          wrote on last edited by
          #4

          I'll add a different approach to sathish's answer - Since you are adding the button in a datagrid column, you can take advantage of event bubbling within the datagrid. Assign a CommandName (and optionally CommandArgument to the button (these are properties of the button). Then in the code handler for the DataGrid's ItemCommand event, you can determine if that command button were clicked by it's CommandName. For example, if you named your button "Details", then your DataGrid ItemCommand handler might look like this:

          void MyGrid_ItemCommand(object o, DataGridCommandEventArgs e)
          {
          if (e.CommandName == "Details")
          {
          // do something when "Details" is clicked...
          // perhaps check e.CommandArgument to get to additional
          // data assigned to the button...
          }
          }

          It's typical to use a switch statement in an ItemCommand handler if you have several buttons with CommandName's in your datagrid.

          1 Reply Last reply
          0
          • S SIJUTHOMASP

            Hai, I have added button using property builder in datagrid. I want to execute some functions under this button click.How I can get the server side events of that button.How I can do this? Please show me the right way. Thank You, Rahul.P.Menon.

            N Offline
            N Offline
            narendrakumarp
            wrote on last edited by
            #5

            Hi Try this: int tmpid = Convert.ToInt32(datagrid.DataKeys[(int)e.Item.ItemIndex]); string popupScript = "< Script language = 'javascript'>"+ string.Format("javaScript:window.opener.document.{0}.value = \'{1:d}\';window.close(0;", request.QueryString["field"], Convert.ToInt32(tmpid)) + ""; Page.RegisterClientScriptBlock("PopupScript",popupScript); In Properties of DataGrid, This Code as to be written in "ItemCommand" Event. Regards, Naren please help me

            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