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. GridView OnClick and OndblCick Attributes in RowDataBound

GridView OnClick and OndblCick Attributes in RowDataBound

Scheduled Pinned Locked Moved ASP.NET
help
2 Posts 2 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.
  • V Offline
    V Offline
    vishnukamath
    wrote on last edited by
    #1

    Hi , I need to add OnClick and OndblCick Attributes in RowDataBound event , OnClick for get first cell value and store it in Session and OndblCick for redirecting to newpage.aspx.I tried with below code in RowDataBound, and i'm not using template fields for gridview directly bindig datasource(template fileds not require for me). e.Row.Attributes["ondblclick"] = ClientScript.GetPostBackClientHyperlink(this.gv_commondataList, "Select$" + e.Row.RowIndex,true); ----- single Click : ------------ i added one btn_Hidden control in Display none Div tag. This Button Click event firing properly but gv_commondataList_SelectedIndexChanged event not firing on row Double Click e.Row.Attributes.Add("onclick", "document.getElementById('" + hd_ItemValue.ClientID + "').value=" + e.Row.RowIndex + ";document.getElementById('" + btn_Hidden.ClientID + "').click();"); Could you please suggest me better way to solve my problem. Regards, vishnu.

    H 1 Reply Last reply
    0
    • V vishnukamath

      Hi , I need to add OnClick and OndblCick Attributes in RowDataBound event , OnClick for get first cell value and store it in Session and OndblCick for redirecting to newpage.aspx.I tried with below code in RowDataBound, and i'm not using template fields for gridview directly bindig datasource(template fileds not require for me). e.Row.Attributes["ondblclick"] = ClientScript.GetPostBackClientHyperlink(this.gv_commondataList, "Select$" + e.Row.RowIndex,true); ----- single Click : ------------ i added one btn_Hidden control in Display none Div tag. This Button Click event firing properly but gv_commondataList_SelectedIndexChanged event not firing on row Double Click e.Row.Attributes.Add("onclick", "document.getElementById('" + hd_ItemValue.ClientID + "').value=" + e.Row.RowIndex + ";document.getElementById('" + btn_Hidden.ClientID + "').click();"); Could you please suggest me better way to solve my problem. Regards, vishnu.

      H Offline
      H Offline
      Hanzaplast
      wrote on last edited by
      #2

      hi. you can solve problem using asp.net ajax - WebMethods. use this code:

      void myGv_RowDataBound(object sender, GridViewRowEventArgs e)
      {
      string value = e.Row.Cells[0].Text;

      e.Row.Attributes\["onclick"\] = "PageMethods.InitSession('"+value+"')";
      e.Row.Attributes\["ondblclick"\] = "window.location='something.aspx'";
      

      }
      [System.Web.Services.WebMethod()]
      public static void InitSession(string value)
      {
      Page page = (System.Web.HttpContext.Current.CurrentHandler as Page);
      page.Session["Test"] = value;
      }

      and add this markup on your aspx

      <asp:ScriptManager runat="server" ID="sm" EnablePageMethods="true" />

      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