【问题标题】:Cannot cause $(this).find("a").click(); to fire using JQuery不能导致 $(this).find("a").click();使用 JQuery 触发
【发布时间】:2011-02-27 06:15:26
【问题描述】:

我有一个小问题,对于 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 上,我有我想要触发的服务器端方法。 任何想法都会受到赞赏。

谢谢, 阿里

【问题讨论】:

  • 可以给我看看asp代码生成的html吗?
  • 你的javascript在哪里? this 是相对的,不知道你来自哪里,这是一个盲目的猜测。

标签: asp.net jquery thickbox double-click gridviewrow


【解决方案1】:

查看链接下方的脚本没有被点击,因为设置了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>

【讨论】:

  • 删除了 window.location 但没有任何乐趣。有没有实现相同目标的替代方法?即从gridview行双击调用服务器端方法?或者显示一个包含双击行详细信息的弹出窗口?基本上我没有经常使用 JavaScript 和 JQuery,所以我对这些不太满意。
  • 这篇博文中的技术看起来很有说服力,因为我已经显示了来自服务器端方法的 jquery 弹出窗口。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多