Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GridView-使用javascript从网格数据行中的控件更改页脚_C#_Javascript_Asp.net_Gridview - Fatal编程技术网

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

C# GridView-使用javascript从网格数据行中的控件更改页脚,c#,javascript,asp.net,gridview,C#,Javascript,Asp.net,Gridview,我有一个GridView如下 <asp:GridView ID="grdProducts" runat="server" AutoGenerateColumns="false" OnRowCommand="grdProducts_RowCommand" OnRowDataBound="grdProducts_RowDataBound" ShowFooter="true"> <Columns>

我有一个
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>
和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>
Label lblGrandTotal= (Label)grdProducts.FooterRow.FindControl("lblGrandTotal");

函数计算总计(数量、单价、总计){
document.getElementById(总计).innerHTML=(parseFloat(document.getElementById(数量).value)*parseFloat(document.getElementById(单价).innerHTML)).toFixed(2);
}

现在我想知道如何在同一个js函数中更改页脚中
lblGrandTotal
的文本,但是不能像访问row元素那样访问页脚元素。如何执行此操作?

在rowDatabound事件中使用类似的方法查找页脚标签并在javascript中添加其id

<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>
Label lblGrandTotal= (Label)grdProducts.FooterRow.FindControl("lblGrandTotal");

假设我找到了该控件,那么如何将该控件的客户端id传递给js函数,因为textbox的事件是在满足
if(e.Row.RowType==DataControlRowType.DataRow)
后编写的?您可以在if(e.Row.RowType==DataControlRowType.DataRow)中使用这一行,因为它直接查看页脚行(这显然只有一个)和其他人一样,你也可以使用lblGrandTotal.clientid这是我第一次尝试…然后我意识到,页脚标签不是DataRow的一部分,那么如何在那里找到它:P;)你使用的是TextBox txtQty=(TextBox)e.Row.FindControl(“txtQty”);它正在查看当前数据行和(标签)grdProducts.FooterRow.FindControl(“lblGrandTotal”)直接查看页脚行。在这里,您在数据行中找不到页脚元素。在这里,您在当前数据行中找到页脚元素,您要将数据绑定到该数据行。:)