首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >GridView -使用javascript更改网格数据行中控件的页脚

GridView -使用javascript更改网格数据行中控件的页脚
EN

Stack Overflow用户
提问于 2014-06-12 11:08:58
回答 1查看 1.6K关注 0票数 0

我有一个GridView,如下所示

代码语言:javascript
运行
复制
<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>

我一直在使用以下代码更改“lblTotalPrice”值

代码语言:javascript
运行
复制
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)
            {
            }
        }

和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>

现在,我想知道如何在同样的js函数中更改脚注中的lblGrandTotal文本,但不能访问行元素的脚注元素。我该怎么做?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-12 11:19:16

在您的rowDatabound事件中使用下面这样的方法来查找页脚,并在javascript中添加它的id

代码语言:javascript
运行
复制
Label lblGrandTotal= (Label)grdProducts.FooterRow.FindControl("lblGrandTotal");
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24182867

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档