请教一个问题,asp.net 对表格的操作 如下:
    grid行上有 两个可以入力的文本框A和B,还有C文本框,要求在A,B内输入之后进行乘积计算,焦点离开后结果放在C里面。这个功能怎么实现阿!是否要写脚本!

解决方案 »

  1.   

    function MyAmt(txt_price,txt_qty,txt_amt)
    {   
        var price= parseFloat((document.getElementById(txt_price)).value);
        var qty=parseFloat((document.getElementById(txt_qty)).value);
        var amt=price*qty;
          (document.getElementById(txt_amt)).value=Math.round(amt*100)/100;     
    }
      

  2.   

       this.Txt_Price.Attributes.Add("onblur", "MyAmt('" + Txt_Price.ClientID + "','" + Txt_Qty.ClientID + "','" + Txt_Amt.ClientID + "')");
                this.Txt_Qty.Attributes.Add("onblur", "MyAmt('" + Txt_Price.ClientID + "','" + Txt_Qty.ClientID + "','" + Txt_Amt.ClientID + "')");
      

  3.   

    离开A焦点()
    {
        var a = enent.srcElement;
        var b = a.parentNode.parentNode.cells[n].childNodes[m];
        var c = a.parentNode.parentNode.cells[i].childNodes[m];
        //剩下的就不用我写了吧
    }离开B焦点()
    {
        var a = enent.srcElement;
        var b = a.parentNode.parentNode.cells[n].childNodes[m];
        var c = a.parentNode.parentNode.cells[i].childNodes[m];
        //剩下的就不用我写了吧
    }
      

  4.   

    jianzi1943:想问问你你的写法是操作当前行的吗? 我的Grid上有很多行阿!
      

  5.   

     protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
        { 
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                TextBox Txt_Price = (TextBox)e.Item.FindControl("Txt_Price");
                TextBox Txt_Qty = (TextBox)e.Item.FindControl("Txt_Qty");
                TextBox Txt_Amt = (TextBox)e.Item.FindControl("Txt_Amt");            Txt_Price.Attributes.Add("onblur", "MyAmt('" + Txt_Price.ClientID + "','" + Txt_Qty.ClientID + "','" + Txt_Amt.ClientID + "')");
                Txt_Qty.Attributes.Add("onblur", "MyAmt('" + Txt_Price.ClientID + "','" + Txt_Qty.ClientID + "','" + Txt_Amt.ClientID + "')");
            }
    }
      

  6.   

      protected   void   DataGrid1_ItemDataBound(object   sender,   DataGridItemEventArgs   e) 
            {   
    if   (e.Item.ItemType   ==   ListItemType.Item   ¦ ¦   e.Item.ItemType   ==   ListItemType.AlternatingItem) 
                    { 
                            TextBox   Txt_Price   =   (TextBox)e.Item.FindControl("Txt_Price"); 
                            TextBox   Txt_Qty   =   (TextBox)e.Item.FindControl("Txt_Qty"); 
                            TextBox   Txt_Amt   =   (TextBox)e.Item.FindControl("Txt_Amt");                         Txt_Price.Attributes.Add("onblur",   "MyAmt('"   +   Txt_Price.ClientID   +   "','"   +   Txt_Qty.ClientID   +   "','"   +   Txt_Amt.ClientID   +   "')"); 
                            Txt_Qty.Attributes.Add("onblur",   "MyAmt('"   +   Txt_Price.ClientID   +   "','"   +   Txt_Qty.ClientID   +   "','"   +   Txt_Amt.ClientID   +   "')"); 
                    } 
    }
      

  7.   

    jianzi1943:可以用于当前行吗,我的grid有很多行啊?
      

  8.   

    vb.net 里面 DataGridItemEventArgs   这个怎么用阿
      

  9.   

      Protected Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
            If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
                Dim Txt_Price As New TextBox
                Dim Txt_Qty As New TextBox
                Dim Txt_Amt As New TextBox            Txt_Price = CType(e.Item.FindControl("Txt_Price"), TextBox)
                Txt_Qty = CType(e.Item.FindControl("Txt_Qty"), TextBox)
                Txt_Amt = CType(e.Item.FindControl("Txt_Amt"), TextBox)            Txt_Price.Attributes.Add("onblur", "MyAmt('" + Txt_Price.ClientID + "','" + Txt_Qty.ClientID + "','" + Txt_Amt.ClientID + "')")
                Txt_Qty.Attributes.Add("onblur", "MyAmt('" + Txt_Price.ClientID + "','" + Txt_Qty.ClientID + "','" + Txt_Amt.ClientID + "')")        End If
        End Sub