【发布时间】: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);
});
我相信您可以在第一眼看到它不起作用。这样做的正确方法是什么?
【问题讨论】: