javascript 遍历c# 2005  datagridview 中的模板编辑框的问题
我想作这样的功能  datagridview 中有 这样明细 价格 数量 金额 
这个在页面上输入 数量后能根据 价格×数量 得出金额 并写到 金额的编辑框中
注意要用 javascript实现这样才能不刷新的及时反应出。请给出完整代码,谢谢。

解决方案 »

  1.   

    javascript 遍历c# 2005  datagridview 中的模板编辑框的问题
    ==
    应该是GridView吧?
      

  2.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="productdetail.aspx.cs" Inherits="productdetail" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
        <script type="text/javascript">
         function setValue(price ,qty, count)
        {
            document.getElementById(count).innerText = parseFloat(document.getElementById(price).innerText) * parseInt(document.getElementById(qty).value);
        }   
        </script></head>
    <body>
        <form id="form1" runat="server">
        <div>
    <asp:GridView ID="GridView1" runat="server" autogeneratecolumns="False" datakeynames="OrderID,ProductID" datasourceid="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound">
    <Columns>
        <asp:BoundField DataField="OrderID" HeaderText="OrderID" ReadOnly="True" SortExpression="OrderID" />
        <asp:BoundField DataField="ProductID" HeaderText="ProductID" ReadOnly="True" SortExpression="ProductID" />
        <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
        <asp:TemplateField HeaderText="UnitPrice" SortExpression="UnitPrice">
            <ItemTemplate>
                <asp:Label ID="lblUnitPrice" runat="server" Text='<%# Eval("UnitPrice") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Quantity" SortExpression="Quantity">
            <ItemTemplate>
                <asp:TextBox ID="txtQuantity" runat="server" Text='<%# Eval("Quantity") %>'></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Count">
            <ItemTemplate>
                <asp:Label ID="lblCount" runat="server" Text='<%# Convert.ToDecimal(Eval("UnitPrice")) * Convert.ToInt32(Eval("Quantity"))%>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" connectionstring="Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True" providername="System.Data.SqlClient" selectcommand="select * from [order details]"></asp:SqlDataSource>
        </div>
        </form>
    </body>
    </html>public partial class productdetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Label price;
            TextBox qty;
            Label count;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                price = e.Row.FindControl("lblUnitPrice") as Label;
                qty = e.Row.FindControl("txtQuantity") as TextBox;
                count = e.Row.FindControl("lblCount") as Label;            qty.Attributes.Add("onblur", "setValue('" + price.ClientID + "','" + qty.ClientID + "','" + count.ClientID + "')");
            }
        }
    }