title: Double Click Row of GridView
body: <p>I want to be able to double click the row of a <code>GridView</code> and be redirected to a page that shows the details of the row that was clicked. </p>
  
  <p>I have code that I'm working with and it seems like it should work, but I'm getting the error "Object reference not set to an instance of an object".</p>
  
  <p>For some reason the row comes up null and I'm unsure why.  My code is below.  Can someone see what I'm doing wrong?</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" EnableViewState="true" OnDataBound="GridView1_DataBound" OnRowDataBound="GridView1_RowDataBound"
      AllowSorting="True" AutoGenerateColumns="False" BorderStyle="Solid" GridLines="Both" HeaderStyle-BackColor="#990033" Width="1000px" 
      DataSourceID="EntityDataSource1"&gt;
       &lt;HeaderStyle ForeColor="White"&gt;&lt;/HeaderStyle&gt;
      &lt;Columns&gt;            
          &lt;asp:TemplateField&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:HyperLink ID="HyperLink1" runat="server" Text='&lt;%# Bind("intBatchID") %&gt;' NavigateUrl="TestPage1.aspx?intBatchID={0}" Target="_blank"&gt;&lt;/asp:HyperLink&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:BoundField DataField="vcharName" HeaderText="Name" ReadOnly="True" 
              SortExpression="vcharName" /&gt;
          &lt;asp:BoundField DataField="dtmScheduled" HeaderText="Date Scheduled" 
              ReadOnly="True" SortExpression="dtmScheduled" /&gt;
          &lt;asp:BoundField DataField="intBatchPriorityLevel" 
              HeaderText="Priority Level" ReadOnly="True" 
              SortExpression="intBatchPriorityLevel" /&gt;
      &lt;/Columns&gt;
      &lt;PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" PageButtonCount="4" PreviousPageText="Previous" NextPageText="Next" FirstPageText="First" LastPageText="Last" /&gt;
      &lt;PagerStyle HorizontalAlign="Center" /&gt;        
  &lt;/asp:GridView&gt;   
  You are viewing page &lt;%=GridView1.PageIndex + 1%&gt; of &lt;%=GridView1.PageCount%&gt;
  &lt;asp:EntityDataSource ID="EntityDataSource1" runat="server" OnSelected="EntityDataSource1_Selected"  
      ConnectionString="name=TestEntities" DefaultContainerName="TestEntities" 
      EnableFlattening="False" EntitySetName="tbl_Batch" 
      Select="it.[intBatchID], it.[vcharName], it.[dtmScheduled], it.[intBatchPriorityLevel]" OrderBy="it.[intBatchID]"&gt;
  &lt;/asp:EntityDataSource&gt;
  
  
  
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              System.Data.DataRowView drv = e.Row.DataItem as System.Data.DataRowView;
              e.Row.Attributes.Add("ondblclick", String.Format("window.location='TestPage1.aspx?intBatchID={0}'", drv["intBatchID"]));
          }
  
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              e.Row.Attributes.Add("onMouseOver", "Highlight(this)");
              e.Row.Attributes.Add("onMouseOut", "UnHighlight(this)");
          }
      }
  </code></pre>