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 use click event of button in itemtemplate of datalist.

how to use click event of button in itemtemplate of datalist.

Scheduled Pinned Locked Moved ASP.NET
helptutorial
11 Posts 5 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 monuSaini

    Hello every body, I want to use an button in item template of datalist and i want dat on the click event of button the page should to redirected to the given url. But i am unable to do dat . pleae help me Regards Rahul rahul saini

    R Offline
    R Offline
    RaviJJain
    wrote on last edited by
    #2

    there is a property of button commandname set commandname="Button1" and on the click of the button in itemcommand event of the datalist you can trace the button by its command name and can code accordingly.

    M 1 Reply Last reply
    0
    • M monuSaini

      Hello every body, I want to use an button in item template of datalist and i want dat on the click event of button the page should to redirected to the given url. But i am unable to do dat . pleae help me Regards Rahul rahul saini

      H Offline
      H Offline
      Harini N K
      wrote on last edited by
      #3

      Hi Give a method name for the onclick event of Button. You can add code behind for that button event. For example

      protected void Button1_Onclick(object sender, EventArgs e)
      {
      Response.Redirect("Default2.aspx");
      }

      Make sure that in your .aspx you have added OnClick event for the button. Method name can be anything but should be same as the code behind file. Hope this is clear.

      Harini

      M 1 Reply Last reply
      0
      • R RaviJJain

        there is a property of button commandname set commandname="Button1" and on the click of the button in itemcommand event of the datalist you can trace the button by its command name and can code accordingly.

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

        Hi Ravi Thanks for rplying my post. Can u send me an example of dis. I am not getting ur point. I have assigned commandname. but wat to do next.... Please send me an example with code Thanks Rahul rahul saini

        R 1 Reply Last reply
        0
        • H Harini N K

          Hi Give a method name for the onclick event of Button. You can add code behind for that button event. For example

          protected void Button1_Onclick(object sender, EventArgs e)
          {
          Response.Redirect("Default2.aspx");
          }

          Make sure that in your .aspx you have added OnClick event for the button. Method name can be anything but should be same as the code behind file. Hope this is clear.

          Harini

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

          Hello Harini, Thanks for ur rply. But my button is in itemList in dataList. Thanks Rahul rahul saini

          _ 1 Reply Last reply
          0
          • M monuSaini

            Hi Ravi Thanks for rplying my post. Can u send me an example of dis. I am not getting ur point. I have assigned commandname. but wat to do next.... Please send me an example with code Thanks Rahul rahul saini

            R Offline
            R Offline
            RaviJJain
            wrote on last edited by
            #6

            in the vb file Private Sub datalist1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles datalist1.ItemCommand if e.commandname = "button1" then response.redirect("xyz.aspx") endif end sub

            M 1 Reply Last reply
            0
            • M monuSaini

              Hello Harini, Thanks for ur rply. But my button is in itemList in dataList. Thanks Rahul rahul saini

              _ Offline
              _ Offline
              _AK_
              wrote on last edited by
              #7

              You can use the method what ravijjain has suggested.

              Best Regards, Apurva Kaushal

              1 Reply Last reply
              0
              • R RaviJJain

                in the vb file Private Sub datalist1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles datalist1.ItemCommand if e.commandname = "button1" then response.redirect("xyz.aspx") endif end sub

                M Offline
                M Offline
                monuSaini
                wrote on last edited by
                #8

                Hi Ravi It is not working. I have use following code in .aspx I have use following code in .vb Sub button_command(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles veiwJobDetails.ItemCommand If e.CommandName = "applyVacancy" Then Response.Redirect("wwww.jjjjdddd.com") End If End Sub But it not redirecting to dat url It is redirecting to the same page. Regards Rahul rahul saini

                R 1 Reply Last reply
                0
                • M monuSaini

                  Hello every body, I want to use an button in item template of datalist and i want dat on the click event of button the page should to redirected to the given url. But i am unable to do dat . pleae help me Regards Rahul rahul saini

                  I Offline
                  I Offline
                  Imran Khan Pathan
                  wrote on last edited by
                  #9

                  hi first set commandname property of datalist button and then write code on ItemCommand event Best regards Pathan

                  GOD HELP THOSE WHO HELP THEMSELVES

                  M 1 Reply Last reply
                  0
                  • I Imran Khan Pathan

                    hi first set commandname property of datalist button and then write code on ItemCommand event Best regards Pathan

                    GOD HELP THOSE WHO HELP THEMSELVES

                    M Offline
                    M Offline
                    monuSaini
                    wrote on last edited by
                    #10

                    Hello Yes i have written commandname property Regards RAHUL rahul saini

                    1 Reply Last reply
                    0
                    • M monuSaini

                      Hi Ravi It is not working. I have use following code in .aspx I have use following code in .vb Sub button_command(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles veiwJobDetails.ItemCommand If e.CommandName = "applyVacancy" Then Response.Redirect("wwww.jjjjdddd.com") End If End Sub But it not redirecting to dat url It is redirecting to the same page. Regards Rahul rahul saini

                      R Offline
                      R Offline
                      RaviJJain
                      wrote on last edited by
                      #11

                      write below code in your aspx page in vb you have done all the things properly..

                      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