如何使用Jquery获取Gridview行值

时间:2013-01-24 09:18:46

标签: asp.net jquery

当我们点击更新按钮时,我需要

日期,客户名称,营业时间,费率,表格日期,截止日期,增值税,服务税,总金额详情..

使用“Jquery”

请帮助我....

我非常感谢你......

    <asp:GridView ID="gvTransactions" CssClass="gridStyle" runat="server" AutoGenerateColumns="false" 
DataKeyNames="fn_transaction_pk"
OnRowDataBound="gvTransactions_RowDataBound"
OnRowDeleting="gvTransactions_RowDeleting"
OnRowEditing="gvTransactions_RowEditing"
OnRowCancelingEdit="gvTransactions_RowCancelingEdit" >
<Columns>
<asp:TemplateField HeaderText="Invoice Details" ItemStyle-Width="90%" >
<ItemTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:HiddenField ID="fn_transaction_pk" runat="server" value='<% #Eval("FN_TRANSACTION_PK")%>' />
<asp:Label ID="lblDate" runat="server" Text="Date : " CssClass="gridLabel1Style" />
</td>
<td><asp:Label ID="ltDate" runat="server" Text='<% #Eval("transaction_date","{0:MM/dd/yyyy}")%>' CssClass="gridLadel2Style" /></td>
</tr>
<tr>
<td><asp:Label ID="lblClientName" runat="server" Text="Client Name : " CssClass="gridLabel1Style"/></td>
<td><asp:Label ID="ltClientName" runat="server" Text='<% #Eval("CLIENT_NAME") %>' CssClass="gridLadel2Style" /></td>
</tr>
<tr>
<td><asp:Label ID="lblNoOfHours" runat="server" Text="Number of Hours : " CssClass="gridLabel1Style" /></td>
<td><asp:Label ID="ltNoOfHours" runat="server" Text='<% #Eval("NO_OF_HOURS") %>' CssClass="gridLadel2Style" /></td>
</tr>
<tr>
<td><asp:Label ID="lblRate" runat="server" Text="Rate : " CssClass="gridLabel1Style" /></td>
<td><asp:Label ID="ltRate" runat="server" Text='<% #Eval("RATE", "{0:0.00}") %>' CssClass="gridLadel2Style" /></td>
</tr>
<tr>
<td><asp:Label ID="lblFromD" runat="server" Text="From Date : " CssClass="gridLabel1Style" /></td>
<td><asp:Label ID="ltFrom" runat="server" Text='<% #Eval("FROM_DATE","{0:MM/dd/yyyy}") %>' CssClass="gridLadel2Style" /></td>
</tr>
<tr>
<td><asp:Label ID="lblToD" runat="server" Text="To Date : " CssClass="gridLabel1Style" /></td>
<td><asp:Label ID="ltTo" runat="server" Text='<% #Eval("TO_DATE","{0:MM/dd/yyyy}") %>' CssClass="gridLadel2Style" /></td> 
</tr>
<tr>
<td><asp:Label ID="lblVAT" runat="server" Text="Value Added Tax(VAT) : " CssClass="gridLabel1Style" /></td>
<td><asp:Label ID="ltVat" runat="server" Text='<% #Eval("VAT", "{0:0.00}") %>' CssClass="gridLadel2Style" /></td>
</tr>
<tr>
<td><asp:Label ID="lblServiceTax" runat="server" Text="Service Tax : " CssClass="gridLabel1Style" /></td>
<td><asp:Label ID="ltServiceTax" runat="server" Text='<% #Eval("SERVICE_TAX", "{0:0.00}") %>' CssClass="gridLadel2Style" /></td>
</tr>
<tr>
<td><asp:Label ID="lblAmount" runat="server" Text="Total Amount : " CssClass="gridLabel1Style" /></td>
<td><asp:Label ID="ltAmount" runat="server" Text='<% #Eval("TOTAL_AMOUNT", "{0:0.00}") %>' CssClass="gridLadel2Style" /></td>
</tr>
</table> 
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtInvDate" runat="server" CssClass="tcal csssmalltextbox" ToolTip="MM/DD/YYYY" />
</EditItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Actions" ItemStyle-CssClass="gridColumnStyle2">
<ItemTemplate>

<asp:Button ID="updateBtn" runat="server" CommandName="select" Text="Update" onclientclick="pageLoad()" />


</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnupdate" runat="server" CommandName="Update" Text="Update" Width="70px" CssClass="updateBtn" />

</EditItemTemplate>
</asp:TemplateField> 
</Columns>
</asp:GridView>

2 个答案:

答案 0 :(得分:4)

只需在ID updateBtn 的更新按钮上添加一个类名,然后尝试此代码

<script type="text/javascript">
        $(document).ready(function () {
            $(".updateBtn").click(function (e) {

                var Client = $(this).closest('tr').find("span[id*=lblClientName]").text();
                var Date = $(this).closest('tr').find("span[id*=ltDate]").text();
                alert(Client);
                e.preventDefault();
            });
        });
    </script>

如果您需要进一步解释,请与我们联系。

答案 1 :(得分:1)

基本上我要做的是:<br/>  1.在asp:LinkBut​​ton模板中添加一个onlclick处理程序,用

调用Javascript函数
 <% #Eval("FN_TRANSACTION_PK")%>' /> as a parameter.<br/>
  1. 在该函数中使用jquery迭代所有表格单元格并重新计算其值。
  2. 将值映射到json对象或类似的东西。
  3. 将其发送到服务器。<br/>
  4. 这应该足以让你走了,对不起 - 我知道一些代码会有所帮助,但我没有时间将其写下来。<br/> 如果您有任何问题,请告诉我。