title: Gridview Edit update Delete by on row click Asp.net
body: <p>Update And Cancel button not functioning and these buttons are out side from the gridview</p>
  
  <p><strong>Scenario:</strong>
  The problem with the default asp.net gridview design is that the GridView edit column always occupies some screen real estate. Additionally in the edit mode the GridView expands horizontally disturbing the page layout. that`s why i want to render an editable GridView without displaying the default Edit, Update and Cancel buttons</p>
  
  <p><strong>Example:</strong> </p>
  
  <p><img src="https://i.stack.imgur.com/l2wXr.png" alt="enter image description here"></p>
  
  <p><strong>What i have done already</strong></p>
  
  <p>when you see the html source of Gridview you will find the following Edit, Update, cancel Link button with an event called dopostback</p>
  
  <p><strong>e.g</strong> </p>
  
  <pre><code>&lt;a href="javascript:__doPostBack(ctl00$ContentPlaceHolder1$GridView2;Edit${1};)"&gt;Edit&lt;/a&gt;
  </code></pre>
  
  <p>If you somehow generate the same above script and execute it for some client side event (click of a button for example) then you can essentially send the same commands to the GridView control. The easiest way to do so is to handle RowDataBound event of the GridView Control so i decided to use it on RowDataBound event of Gridview control as shown below:</p>
  
  <pre><code>protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              if (e.Row.RowIndex == GridView2.EditIndex)
              {
                  //update or cancel buttons
                  LinkButton updateBtn = (LinkButton)e.Row.Cells[0].Controls[0];
                  string updateScript = ClientScript.GetPostBackClientHyperlink(updateBtn, "");
                  Button1.Attributes["onclick"] = updateScript;
  
                  string cancelScript = string.Format("javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView2','Cancel${1}')",
                                        GridView1.ID, e.Row.RowIndex);
                  Button2.Attributes["onclick"] = cancelScript;
              }
              else
              {
                  //edit button
                  string editScript = string.Format("javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView2','Edit${1}')",
                                      GridView1.ID, e.Row.RowIndex);
                  e.Row.Attributes["onclick"] = editScript;
              }
  
          }
          if (GridView2.EditIndex &gt;= 0)
          {
              Button1.Enabled = true;
              Button2.Enabled = true;
          }
          else
          {
              Button1.Enabled = false;
              Button2.Enabled = false;
          }
      }
  </code></pre>
  
  <p>Now when i click on any row of gridview it will become an editable row which should be cancel and update by the cancel and update button which are outside of the gridview but they are not working... </p>
  
  <p>Any help or suggestion would be appreciated .</p>
  
  <p><strong>Note:</strong> still you need to include the edit,update, cancel linkbutton in Gridview which you can latter hide from the gridview by using script like jquery below.. </p>
  
  <p>e.g</p>
  
  <pre><code>$(document).ready(function () {
      $("#GridView2 th:first-child").hide();
      $("#GridView2 td:first-child").hide();
  });
  </code></pre>