Datagrid view double click using jquery with asp.net
<p>I've got a gridView called gvLineItems in an asp.net page..
I want to throw in some jquery to allow for a double click on the row of the gridview and let it redirect to another page:</p>

<pre><code>&lt;script src="include/jquery-1.5.1.min.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;

var selected = null;

$(document).ready(function(){
   $("#divGridView table tbody tr").find("tr").dblclick(function(){
      window.location = "&lt;%#ResolveUrl("~/Default2.aspx")%&gt;?record=" + $(this).find("td:first").text();
   });
});

&lt;/script&gt;
</code></pre>

<p>Does anyone see anything strange here?</p>

<p>Here is the real ugly asp.net ajax with the div etc...</p>

<pre><code>&lt;div id="divGridView" style="width:100%"&gt;
                                &lt;asp:UpdatePanel ID="myPanel" runat="server" &gt;
                                          &lt;ContentTemplate&gt;
                                        &lt;asp:GridView GridLines="Horizontal" CellPadding="4" Font-Size="Small" DataKeyNames="ID" Width="100%" AlternatingRowStyle-BackColor="#F0F8FF" BackColor="#E8E8E8" HeaderStyle-BackColor="#377CB1" ID="gvLineItems" runat="server" AllowSorting="True" AutoGenerateColumns="False" ShowFooter="True" &gt;
                                            &lt;Columns&gt;

                                                  &lt;asp:TemplateField HeaderText="ID" SortExpression="ID" Visible="False"&gt;
                                                     &lt;ItemTemplate&gt;
                                                         &lt;asp:Label ID="lblExpenseReportLineItemID" runat="server" Text='&lt;%# DataBinder.Eval(Container, "DataItem.ID") %&gt;'&gt;&lt;/asp:Label&gt;
                                                     &lt;/ItemTemplate&gt;
                                                  &lt;/asp:TemplateField&gt;

                                                  &lt;asp:TemplateField&gt;
                                                    &lt;HeaderTemplate&gt;
                                                        &lt;asp:CheckBox ID="HeaderLevelCheckBox" AutoPostBack="true" OnCheckedChanged="SelectAllRows" runat="server" /&gt;
                                                    &lt;/HeaderTemplate&gt;
                                                    &lt;ItemTemplate&gt;
                                                        &lt;asp:CheckBox ID="chkSelector" runat="server" onclick="ChangeRowColor(this)" /&gt;
                                                    &lt;/ItemTemplate&gt;
                                                    &lt;ItemStyle HorizontalAlign="Center" Width="1%" /&gt;
                                                    &lt;HeaderStyle HorizontalAlign="Center" Width="1%" /&gt;
                                                  &lt;/asp:TemplateField&gt;   

                                                    &lt;asp:TemplateField&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:ImageButton ID="ibAddLineItem" runat="server" ImageUrl="images/InsertRow.gif"   CommandName="Insert" ToolTip="Insert line item" /&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;ItemStyle Width="1%" /&gt;
                                                    &lt;/asp:TemplateField&gt;

                                                     &lt;asp:TemplateField&gt;
                                                &lt;ItemTemplate&gt;

                                                        &lt;asp:ImageButton ID="ibDelete" runat="server" CommandName="DeleteRow" ImageUrl="images/d.gif"
                                                            ToolTip="Delete Line Item?" /&gt;

                                                &lt;/ItemTemplate&gt;
                                            &lt;/asp:TemplateField&gt;

                                                    &lt;asp:TemplateField HeaderText="Item Date" SortExpression="LineItemDate"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;ajaxToolkit:CalendarExtender TargetControlID="txtLineItemDate" ID="CalendarExtender3" runat="server"&gt;
                                                            &lt;/ajaxToolkit:CalendarExtender&gt;
                                                            &lt;asp:TextBox  Width="60px" onchange='return isLessThanEndDate(this);' ID="txtLineItemDate" runat="server" Text='&lt;%# DataBinder.Eval(Container, "DataItem.LineItemDate") %&gt;'&gt;
                                                            &lt;/asp:TextBox&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;ItemStyle HorizontalAlign="Center" Width="10%" /&gt;
                                                        &lt;HeaderStyle ForeColor="White" HorizontalAlign="Center" Width="12%" /&gt;
                                                    &lt;/asp:TemplateField&gt;             

                                                    &lt;asp:TemplateField HeaderText="Comm.CU" SortExpression="Comm"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;table width="100%" cellpadding="2" cellspacing="0" style=" border-style:solid; border-width:thin; border-color:#DDD;"&gt;
                                                                &lt;tr&gt;
                                                                &lt;td &gt;&lt;asp:TextBox Enabled="False" ToolTip="Click Search...To find a commission" Width="40px" ID="txtComm" runat="server" Text='&lt;%# DataBinder.Eval(Container, "DataItem.CommissionID") %&gt;' /&gt;&lt;/td&gt;
                                                                &lt;/tr&gt;
                                                                &lt;tr&gt;&lt;td&gt;&lt;asp:TextBox Enabled="False" ToolTip="Click Search...To find a cost unit" Width="40px" ID="txtWBS" runat="server" Text='&lt;%# DataBinder.Eval(Container, "DataItem.WBSID") %&gt;' /&gt;&lt;/td&gt;&lt;/tr&gt;
                                                                &lt;tr&gt;&lt;td align="center"&gt;&lt;a href='FindCommCost.aspx?ExpenseReportID=&lt;%#Eval("ERID")%&gt;&amp;ExpenseReportLineItemID=&lt;%#Eval("ID")%&gt;'  style="color:Navy"&gt;Search...&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
                                                            &lt;/table&gt;



                                                        &lt;/ItemTemplate&gt;
                                                        &lt;ItemStyle Width="1%" /&gt;
                                                    &lt;/asp:TemplateField&gt;


                                                    &lt;asp:TemplateField HeaderText="Type" SortExpression="Reason"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:DropDownList ID="ddlExpenseTypes" OnSelectedIndexChanged="ddlExpenseTypes_SelectedIndexChanged"  DataSource='&lt;%# GetExpenseTypes() %&gt;' SelectedValue='&lt;%# Bind("ExpenseReasonID") %&gt;' DataTextField="ExpenseReasonID" DataValueField="ExpenseReasonID" AutoPostBack="true"  runat="server" &gt;&lt;/asp:DropDownList&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;ItemStyle HorizontalAlign="Center" Width="1%" /&gt;
                                                    &lt;/asp:TemplateField&gt;  

                                                    &lt;asp:TemplateField HeaderText="Receipt" SortExpression="Date"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:CheckBox ID="cbReceipt" runat="server" Checked='&lt;%# DataBinder.Eval(Container, "DataItem.HasReceipt") %&gt;' /&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;HeaderStyle ForeColor="White" /&gt;
                                                        &lt;ItemStyle HorizontalAlign="Center" Width="1%" /&gt;
                                                    &lt;/asp:TemplateField&gt;             

                                                    &lt;asp:TemplateField HeaderText="Amount" SortExpression="Amount"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:TextBox Width="40px" AutoPostBack="true" OnTextChanged="ChangedAmount" ID="txtAmount" runat="server" Text='&lt;%# DataBinder.Eval(Container, "DataItem.AmountSpent") %&gt;' /&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;ItemStyle Width="1%" /&gt;
                                                    &lt;/asp:TemplateField&gt;

                                                     &lt;asp:TemplateField HeaderText="Currency" SortExpression="Currency"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:DropDownList ID="ddlCurrency" OnSelectedIndexChanged="ddlCurrency_SelectedIndexChanged" runat="server" AutoPostBack="true" DataSource='&lt;%# GetCurrency() %&gt;' SelectedValue='&lt;%# Bind("CountryID") %&gt;' DataTextField="CountryID" DataValueField="CountryID"&gt;&lt;/asp:DropDownList&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;ItemStyle HorizontalAlign="Center" Width="1%" /&gt;
                                                    &lt;/asp:TemplateField&gt;  

                                                    &lt;asp:TemplateField HeaderText="Rate" SortExpression="Rate"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:TextBox Width="33px" AutoPostBack="true" ID="txtRate" OnTextChanged="ChangedAmount" runat="server" Text='&lt;%# DataBinder.Eval(Container, "DataItem.Rate") %&gt;' /&gt; 
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;ItemStyle Width="1%" /&gt;
                                                    &lt;/asp:TemplateField&gt;

                                                    &lt;asp:TemplateField HeaderText="USD" SortExpression="USD"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:Label ID="lblUSD" runat="server"  Text='&lt;%# DataBinder.Eval(Container, "DataItem.AmountBackInUSD") %&gt;' /&gt; 
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;ItemStyle Width="1%" /&gt;
                                                    &lt;/asp:TemplateField&gt;

                                                    &lt;asp:TemplateField HeaderText="Desc." SortExpression="Desc."&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:TextBox Width="100px" Font-Names="Arial" ToolTip="If the expense type is Entertainment this field is required!" ID="txtExpenseReasonDescription" runat="server" Text='&lt;%# DataBinder.Eval(Container, "DataItem.ExpenseReasonDescription") %&gt;' /&gt; 
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;ItemStyle Width="1%" HorizontalAlign="Left" /&gt;
                                                    &lt;/asp:TemplateField&gt;


                                                     &lt;asp:HyperLinkField HeaderText="Link" SortExpression="Link" DataNavigateUrlFields="AttachmentLink" DataNavigateUrlFormatString="{0}"
                                                DataTextField="AttachmentLink" DataTextFormatString="Link" Target="_blank" &gt;
                                                         &lt;ControlStyle ForeColor="Navy" /&gt;
                                                         &lt;HeaderStyle ForeColor="White" /&gt;
                                                     &lt;/asp:HyperLinkField&gt;

                                                    &lt;asp:TemplateField HeaderText="Upload File?" SortExpression="ID" &gt;
                                                    &lt;ItemTemplate&gt;
                                                        &lt;asp:FileUpload Width="90px" Font-Size="xx-small"  ID="fuAttachment" runat="server" /&gt;
                                                        &lt;asp:Button ID="btnUpload" font-size="xx-small" runat="server" Text="Upload" OnClick="UploadTheFile" /&gt;
                                                    &lt;/ItemTemplate&gt;
                                                        &lt;HeaderStyle ForeColor="White" /&gt;
                                                        &lt;ItemStyle Width="50%" /&gt;
                                                    &lt;/asp:TemplateField&gt;
                                            &lt;/Columns&gt;
                                            &lt;HeaderStyle BackColor="#377CB1" /&gt;
                                            &lt;AlternatingRowStyle BackColor="AliceBlue" /&gt;
                                            &lt;FooterStyle CssClass="FooterStyle" /&gt;
                                        &lt;/asp:GridView&gt;
                                        &lt;div style="width:100%"&gt;
                                            &lt;br /&gt;
                                    &lt;asp:UpdateProgress ID="udProgress" runat="server" DisplayAfter="100" Visible="True" DynamicLayout="True"&gt;&lt;ProgressTemplate&gt;&lt;img border="0" src="images/loading.gif" alt="loading" /&gt;&lt;/ProgressTemplate&gt;&lt;/asp:UpdateProgress&gt;
                                            &lt;br /&gt;
                                            &lt;asp:Label ID="lblMessage2" runat="server"&gt;&lt;/asp:Label&gt;
                                        &lt;/div&gt;
                                        &lt;div style="width:100%; text-align:right;"&gt;
                                        &lt;table width="100%" cellpadding="2" cellspacing="0"&gt;
                                        &lt;tr&gt;
                                        &lt;td class="tableFields" style="height: 68px"&gt;
                                            &amp;nbsp;&lt;/td&gt;
                                        &lt;td align="right"&gt;
                                        &lt;asp:Panel ID="pGridControls" runat="server" Width="100%" Visible="False"&gt;
                                            &lt;asp:Label ID="Label2" runat="server" Text="Click Update to &lt;u&gt;save&lt;/u&gt; any changes" Font-Bold="True" ForeColor="#377CB1"&gt;&lt;/asp:Label&gt;
                                        &lt;asp:ImageButton ID="ibSaveGrid" runat="server" ImageUrl="images/smallSave.gif" ToolTip="Save / refresh changes?" CausesValidation="False" OnClick="ibSaveGrid_Click" /&gt;&lt;asp:ImageButton ID="ibDeleteGrid" runat="server" ImageUrl="images/smallDelete.gif" ToolTip="Delete checked rows?" CausesValidation="False" OnClick="ibDeleteGrid_Click" /&gt;&lt;/asp:Panel&gt;
                                            &lt;hr /&gt; &lt;h3&gt;
                                                &lt;asp:Panel ID="Panel5" runat="server" Width="50%" HorizontalAlign="Right" BackColor= "#F0FFF0" CssClass="PadIt"&gt;
                                                    &lt;ajaxToolkit:RoundedCornersExtender ID="RoundedCornersExtender4" runat="server" TargetControlID="Panel5" Radius="6" Corners="All" BorderColor="#377CB1" Color="#F0FFF0"&gt;
                                                    &lt;/ajaxToolkit:RoundedCornersExtender&gt;
                                                Employee Due (USD):&lt;asp:Label ID="lblMessage3" runat="server"&gt;&lt;/asp:Label&gt;
                                                &lt;/asp:Panel&gt;
                                                &lt;/h3&gt; &lt;/td&gt;
                                        &lt;/tr&gt;
                                        &lt;/table&gt;
                                        &lt;/div&gt;
                                    &lt;/ContentTemplate&gt;
                                    &lt;Triggers&gt;
                                        &lt;asp:AsyncPostBackTrigger ControlID="ibOk" /&gt;
                                        &lt;asp:AsyncPostBackTrigger ControlID="rbSort" /&gt;
                                    &lt;/Triggers&gt;
                                &lt;/asp:UpdatePanel&gt;
                                    &lt;asp:Literal ID="CheckBoxIDsArray" runat="server"&gt;&lt;/asp:Literal&gt;&lt;/div&gt;
                                &lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                            &lt;/asp:Panel&gt;
                    &lt;/div&gt;
</code></pre>

<p><strong>Here's my edit:</strong></p>

<pre><code>&lt;script type="text/javascript"&gt;

var selected = null;

$(document).ready(function(){
   $("#divGridView table tbody tr").dblclick(function(){
      window.location = "&lt;%#ResolveUrl("~/Default2.aspx")%&gt;?ID=" + $(this).find("td:first").text();
   });
});

&lt;/script&gt;
</code></pre>

<p>I've now almost got it working...I can see the correct ID number, got to work on why the redirect isnt working.</p>
