0

我有一个小问题,对于那里的 jquery 专家来说应该很容易。我正在尝试关注http://aspdotnetcodebook.blogspot.com/2010/01/page-languagec-autoeventwireuptrue.html以便能够对 gridview 行双击执行操作。我可以很好地重定向到另一个页面(如示例所示),但我不能导致 $(this).find("a").click(); 开火。下面是我的 GridView 标记。

<asp:GridView ID="gvCustomers" runat="server" DataSourceID="odsCustomers" CssClass="datagrid"
        GridLines="None" AutoGenerateColumns="False" DataKeyNames="Customer_ID" PageSize="3"
        AllowPaging="True" AllowSorting="True" OnRowCommand="gvCustomers_RowCommand"
        OnRowDataBound="gvCustomers_RowDataBound">
        <Columns>
            <asp:BoundField DataField="Customer_ID" HeaderText="ID" ReadOnly="true" Visible="false" />
            <asp:BoundField DataField="Customer_FirstName" HeaderText="First Name" ReadOnly="true" />
            <asp:BoundField DataField="Customer_LastName" HeaderText="Last Name" ReadOnly="true" />
            <asp:BoundField DataField="Customer_Email" HeaderText="Email" ReadOnly="true" />
            <asp:BoundField DataField="Customer_Mobile" HeaderText="Mobile" ReadOnly="true" />
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton ID="lnkButton" runat="server" CommandName="showVehicles" CommandArgument='<%# Eval("Customer_ID") %>'
                        ></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <EmptyDataTemplate>
            Sorry No Record Found.
        </EmptyDataTemplate>
    </asp:GridView>

我只是不能按照作者的建议让它工作:/* 或者你可以在你可以触发的行中有一个隐藏的 LinkBut​​ton(Text="" 或未设置)。确保设置 CommandName="Something" 和 CommandArgument="RecordId" */

在 linkBut​​ton 的 OnCommand 上,我有我想触发的服务器端方法。任何想法都会受到赞赏。

谢谢,阿里

4

1 回答 1

0

查看您的链接下方的脚本未单击,因为window.location已设置。阅读博客文章的内容说您要么设置window.location要么使用$(this).find("a").click();,但不能同时使用。

<script type="text/javascript">
    var selected = null;
    $(document).ready(function(){
        $("#gvCustomers").find("tr").click(function(){
            $(selected).removeClass("selected"); $(this).addClass("selected"); selected = this;
        });
        $("#gvCustomers").find("tr").dblclick(function(){
            var Id = $(this).find("td:nth-child(1)").text();
            //window.location = "/CustomersVehiclesWebSite/Default2.aspx?record=" + $(this).find("td:nth-child(1)").text();
            $(this).find("a").click();
        });
     });
     function doPostBack(element) {
     tb_remove();
     setTimeout('__doPostBack(\'' + element.name + '\',\'\')', 500);// 500ms given to thickBox to remove itself
     }
</script>
于 2010-06-03T12:25:23.083 回答