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. Javascript for Gridview Commandfield

Javascript for Gridview Commandfield

Scheduled Pinned Locked Moved ASP.NET
questionjavajavascripttools
3 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.
  • D Offline
    D Offline
    dptalt
    wrote on last edited by
    #1

    One column on my gridview is an asp commandfield. When a user clicks on a row in this column how can I execute a client side java script function instead of the code behind function?

    T S 2 Replies Last reply
    0
    • D dptalt

      One column on my gridview is an asp commandfield. When a user clicks on a row in this column how can I execute a client side java script function instead of the code behind function?

      T Offline
      T Offline
      Tuwing Sabado
      wrote on last edited by
      #2

      Convert your commandfield column as templatefield then replace the item template control by regular html link tag.

      1 Reply Last reply
      0
      • D dptalt

        One column on my gridview is an asp commandfield. When a user clicks on a row in this column how can I execute a client side java script function instead of the code behind function?

        S Offline
        S Offline
        Sathisha N M
        wrote on last edited by
        #3

        GridView Data Manipulation function ConfirmOnDelete(item) { if (confirm("Are you sure to delete: " + item + "?")==true) return true; else return false; } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowState != DataControlRowState.Edit) // check for RowState { if (e.Row.RowType == DataControlRowType.DataRow) //check for RowType { string id = e.Row.Cells[0].Text; // Get the id to be deleted LinkButton lb = (LinkButton)e.Row.Cells[6].Controls[2]; //cast the ShowDeleteButton link to linkbutton if (lb != null) { lb.Attributes.Add("onclick", "return ConfirmOnDelete('" + id + "');"); //attach the JavaScript function with the ID as the paramter } } } }

        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