[英]GridView - Change footer from control in Grid Data Row using javascript
I have a GridView
as below 我有一个
GridView
如下
<asp:GridView ID="grdProducts" runat="server" AutoGenerateColumns="false" OnRowCommand="grdProducts_RowCommand"
OnRowDataBound="grdProducts_RowDataBound" ShowFooter="true">
<Columns>
<asp:BoundField HeaderText="Product" DataField="ProductName" />
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:HiddenField ID="hfMode" runat="server" />
<asp:TextBox ID="txtQty" runat="server" Enabled="false" Text='<%# Eval("Qty") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Price">
<ItemTemplate>
<asp:Label ID="lblUnitPrice" runat="server" Text='<%# String.Format("{0:#,#.####}",Eval("UnitPrice")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Price">
<ItemTemplate>
<asp:Label ID="lblTotalPrice" runat="server" Text='<%# String.Format("{0:#,#.####}",Eval("Total")) %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblGrandTotal" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I have been changing 'lblTotalPrice' value using following code 我一直在使用以下代码更改“ lblTotalPrice”的值
protected void grdProducts_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txtQty = (TextBox)e.Row.FindControl("txtQty");
Label lblUnitPrice = (Label)e.Row.FindControl("lblUnitPrice");
Label lblTotalPrice = (Label)e.Row.FindControl("lblTotalPrice");
txtQty.Attributes.Add("onblur", "CalculateTotal('" + txtQty.ClientID + "','" + lblUnitPrice.ClientID + "','" + lblTotalPrice.ClientID + "')");
}
}
catch (Exception ex)
{
}
}
and javascript 和JavaScript
<script type="text/javascript">
function CalculateTotal(Qty, UnitPrice, Total) {
document.getElementById(Total).innerHTML = (parseFloat(document.getElementById(Qty).value) * parseFloat(document.getElementById(UnitPrice).innerHTML)).toFixed(2);
}
</script>
and its working with no fail, now I am wondering how to change text of lblGrandTotal
in footer in same js function, but one can't access footer element as of row element. 并且它的工作没有失败,现在我想知道如何在同一js函数中的页脚中更改
lblGrandTotal
文本,但是不能访问行元素中的页脚元素。 How can I do this? 我怎样才能做到这一点?
在rowDatabound事件中使用类似这样的内容来查找页脚标签,并在javascript中添加其ID
Label lblGrandTotal= (Label)grdProducts.FooterRow.FindControl("lblGrandTotal");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.