title: Double Clicking GridView Row and Getting Id Value
body: <p>I have a Gridview, and I've made it so that the user can double click a row following the following instructions. 
  <a href="http://www.codeproject.com/Articles/15677/Clickable-and-Double-Clickable-Rows-with-GridView" rel="nofollow">http://www.codeproject.com/Articles/15677/Clickable-and-Double-Clickable-Rows-with-GridView</a></p>
  
  <p>This was the easy part.  Now I need to be able to redirect the user to another page using a querystring.  The querstring will be an id that I need to get from the GridView row that is double clicked.  I'm unsure how to get the id from the GridView row.  I've tried lots of different stuff and it always comes up null.  Here is my code.</p>
  
  <pre><code>&lt;asp:GridView ID="gvAllDOL" runat="server" Visible="False" PageSize="25" AutoGenerateColumns="False" OnDataBound="gvAllDOL_DataBound" DataSourceID="odsDOAll" OnRowDataBound="gvAllDOL_RowDataBound" DataKeyNames="sintDistrictOfficeID" OnRowCommand="gvAllDOL_RowCommand" OnSelectedIndexChanged="gvAllDOL_SelectedIndexChanged"&gt;
                  &lt;Columns&gt;
                      &lt;asp:ButtonField Text="DoubleClick" CommandName="DoubleClick" Visible="false" /&gt;
                      &lt;asp:TemplateField&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="lblid" runat="server" Text='&lt;%# Bind("sintDistrictOfficeID") %&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:BoundField DataField="sintDistrictOfficeID" HeaderText="id" SortExpression="sintDistrictOfficeID" /&gt;     
                      &lt;asp:BoundField DataField="vcharDOLOfficeName" HeaderText="DOL Office Name" SortExpression="vcharDOLOfficeName" /&gt;     
                      &lt;asp:BoundField DataField="vcharDOLCity" HeaderText="City" SortExpression="vcharDOLCity" /&gt;
                      &lt;asp:BoundField DataField="vcharDOLState" HeaderText="State" SortExpression="vcharDOLState" /&gt;
                      &lt;asp:BoundField DataField="intBatchCount" HeaderText="Number Batches" SortExpression="intBatchCount" /&gt;
                      &lt;asp:BoundField DataField="intCaseCount" HeaderText="Number Cases" SortExpression="intCaseCount" /&gt;
                      &lt;asp:BoundField DataField="intExamCount" HeaderText="Number Examiners" SortExpression="intExamCount" /&gt;                        
                  &lt;/Columns&gt;
              &lt;/asp:GridView&gt;
  
    protected void gvAllDOL_RowDataBound(object sender, GridViewRowEventArgs e)
      {            
              e.Row.Attributes.Add("onMouseOver", "Highlight(this);");
              e.Row.Attributes.Add("onMouseOut", "UnHighlight(this);");
  
              //doubleclick
              if (e.Row.RowType == DataControlRowType.DataRow)
              {                  
  
                  // Get the LinkButton control in the second cell
                  LinkButton _doubleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
                  // Get the javascript which is assigned to this LinkButton
                  string _jsDouble =
                  ClientScript.GetPostBackClientHyperlink(_doubleClickButton, "");
                  // Add this JavaScript to the ondblclick Attribute of the row
                  e.Row.Attributes["ondblclick"] = _jsDouble;
              }
  
          }
  
   protected void gvAllDOL_RowCommand(object sender, GridViewCommandEventArgs e)
      {
          string id;
          id = gvAllDOL.SelectedRow.Cells[1].Text;
  
          GridView _gridView = (GridView)sender;
  
          // Get the selected index and the command name
          int _selectedIndex = int.Parse(e.CommandArgument.ToString());
          string _commandName = e.CommandName;
  
  
          switch (_commandName)
          {                
              case ("DoubleClick"):
                  Response.Redirect("~/DOL/View_dol.aspx?id=" + id);                  
                  break;
          }
  
      }     
  
  protected override void Render(HtmlTextWriter writer)
      {
  
          foreach (GridViewRow r in gvAllDOL.Rows)
          {
  
              if (r.RowType == DataControlRowType.DataRow)
              {
                  Page.ClientScript.RegisterForEventValidation
                          (r.UniqueID + "$ctl00");
                  Page.ClientScript.RegisterForEventValidation
                          (r.UniqueID + "$ctl01");
              }
          }
  
          base.Render(writer);
      }
  </code></pre>