You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VB.NET嵌套GridView出现Undefined问题求助

VB.NET嵌套GridView出现Undefined问题求助

各位大神好!我最近在做VB.NET的嵌套GridView,要实现点击展开/收起子表格的功能,照着思路写了代码,结果碰上个棘手的问题——浏览器控制台一直报Undefined错误,点加号图标完全没反应,卡了好半天没头绪,求各位帮忙看看哪里出问题了!

先贴一下我目前的ASPX页面代码:

<asp:GridView ID="dgvPickups" runat="server" AutoGenerateColumns="false" CssClass="Grid" DataKeyNames="PickupID" OnRowDataBound="PickupRowDataBound" >
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <img alt="" style="cursor: pointer" src="Content/plus.png" />
                <img alt="" style="cursor: pointer; display: none" src="Content/minus.png" />
                <div style="display: none" class="childGrid">
                    <asp:GridView ID="dgvPickupDetails" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid">
                        <Columns>
                            <asp:BoundField ItemStyle-Width="150px" DataField="ItemID" HeaderText="项目ID" />
                            <asp:BoundField ItemStyle-Width="150px" DataField="ItemName" HeaderText="项目名称" />
                        </Columns>
                    </asp:GridView>
                </div>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField ItemStyle-Width="150px" DataField="PickupID" HeaderText="取件ID" />
        <asp:BoundField ItemStyle-Width="150px" DataField="PickupDate" HeaderText="取件日期" />
    </Columns>
</asp:GridView>

我还写了控制展开收起的JS代码,逻辑就是点击加号切换成减号,同时显示子表格,反之隐藏:

$("img").click(function () {
    var row = $(this).closest("tr");
    var childDiv = row.find(".childGrid");
    var plusImg = row.find("img[src='Content/plus.png']");
    var minusImg = row.find("img[src='Content/minus.png']");
    
    childDiv.toggle();
    plusImg.toggle();
    minusImg.toggle();
});

后台VB.NET的RowDataBound事件里,我也写了绑定子GridView数据的逻辑:

Protected Sub PickupRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim pickupID As Integer = Convert.ToInt32(dgvPickups.DataKeys(e.Row.RowIndex).Value)
        Dim childGrid As GridView = DirectCast(e.Row.FindControl("dgvPickupDetails"), GridView)
        childGrid.DataSource = GetPickupDetails(pickupID)
        childGrid.DataBind()
    End If
End Sub

Private Function GetPickupDetails(ByVal pickupID As Integer) As DataTable
    Dim dt As New DataTable()
    ' 这里是从数据库查询对应取件ID详情的逻辑,测试过能拿到正确数据
    Return dt
End Function

现在的问题是,页面加载完点击加号完全没反应,打开控制台一看,报的是Uncaught ReferenceError: $ is not defined。我明明已经在页面头部引用了jQuery了啊,路径也核对过没错:

<script src="Scripts/jquery-3.6.0.min.js"></script>

我自己排查了好半天,后台绑定数据是正常的,图片路径也没写错,就是前端点击没反应还报Undefined,有没有大神遇过类似的问题?麻烦给我指个方向!

备注:内容来源于stack exchange,提问作者Jason Guernsey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.16 09:10:32