我有一个gridview视图,其标签为lblPrice,文本框为txtQuanty,另外还有一个标签lblAmount。
<asp:GridView ID="gridItem2" HeaderStyle-BackColor="#FC8D10" HeaderStyle-ForeColor="White"
RowStyle-BackColor="skyblue" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000"
runat="server" AutoGenerateColumns="False" AllowPaging="false" OnPageIndexChanging="gridItems_PageIndexChanging">
<AlternatingRowStyle BackColor="White" ForeColor="#000000" />
<Columns>
<asp:TemplateField>
<HeaderStyle Width="80px" HorizontalAlign="Center" />
<HeaderTemplate>
<p>Action</p>
</HeaderTemplate>
<ItemTemplate>
<asp:ImageButton runat="server" CommandName="cmdDel" CommandArgument='<%#((GridViewRow)Container).RowIndex %>' Height="20" Width="20" />
</ItemTemplate>
<ItemStyle Width="80px" HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField Visible="false">
<HeaderTemplate>
<asp:Label runat="server" Text="txt"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label runat="server" ID="lblItemId" Text='<%#Eval("itemId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true">
<HeaderStyle Width="100px" />
<HeaderTemplate>
<asp:Label runat="server" Text="Items"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label runat="server" ID="lblName" Text='<%#Eval("name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true">
<HeaderStyle Width="120px" />
<HeaderTemplate>
<asp:Label runat="server" Text="Price"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label runat="server" CssClass="clsPrice" ID="lblPrice" Text='<%#Eval("price") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true">
<HeaderStyle Width="120px" />
<HeaderTemplate>
<asp:Label runat="server" Text="Quantity"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox runat="server" onkeyup="myfunctionname(this.value);" CssClass="clsQuant" ID="txtQuant"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true">
<HeaderStyle Width="120px" />
<HeaderTemplate>
<asp:Label runat="server" Text="Total"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label runat="server" ID="lblTotal"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#3AC0F2" ForeColor="White" />
<RowStyle BackColor="#A1DCF2" />
</asp:GridView>
我想在txtAmount上触发onkeyup事件,所以我使用这个jquery
function myfunctionname(amount) {
var myvalue = "";
myvalue=$('#gridItem2 input[type=text]').closest("tr").find(".clsPrice").text();
alert(myvalue);
}
获取标签值但它获得所有标签的值。它不起作用。请提出建议