【问题标题】:Hiding gridview column and get it when clicked隐藏gridview列并在单击时获取它
【发布时间】:2016-04-24 12:52:21
【问题描述】:

我正在尝试学习在 asp.net 中使用 jquery,并且我有一个 gridview。我想在 gridview 中隐藏 userId 但获取单击行的 Id 值。这是我的网格视图:

<asp:GridView ID="addGridControl" CssClass="mGrid"  PagerStyle-CssClass="pgr" AllowPaging="true" PageSize="10" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="EntityDataSource1">
        <Columns>
            <asp:TemplateField Visible="false">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%#Eval("CustomerId") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName"></asp:BoundField>
            <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName"></asp:BoundField>
            <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" SortExpression="ContactTitle"></asp:BoundField>
            <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address"></asp:BoundField>
            <asp:BoundField DataField="City" HeaderText="City" SortExpression="City"></asp:BoundField>
            <asp:BoundField DataField="Region" HeaderText="Region" SortExpression="Region"></asp:BoundField>
            <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode"></asp:BoundField>
            <asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country"></asp:BoundField>
            <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone"></asp:BoundField>
            <asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax"></asp:BoundField>
        </Columns>
    </asp:GridView>

这是我的 jquery 尝试:

$("#addGridControl tr").click(function () {
        var secilen = $(this).closest('tr').find("#Label1").attr("Text");
        alert(secilen);
    });

我相信您可以在第一眼看到它不起作用。这样做的正确方法是什么?

【问题讨论】:

    标签: jquery asp.net gridview


    【解决方案1】:

    你应该替换:

    <asp:TemplateField Visible="false">
    

    <asp:TemplateField HeaderStyle-CssClass="notVisible" ItemStyle-CssClass="notVisible" FooterStyle-CssClass="notVisible">
    

    与类风格:

    .notVisible
    {
        display: none;
    }
    

    Visible 属性设置为false 时,ASP.NET 会从 HTML 输出中删除该控件。因此,客户端代码将找不到它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-29
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多