1

我有一个网格视图,我想用 JavaScript 来计算在文本框中输入的值。

我正在添加onkeyuponrowcreated函数中的文本框,它工作正常。

然后我把gridview放在amultiview中,它停止工作。

这是我的 JavaScript 函数:

   function margin1(rowIndex, price, gridId) {
        var grid = document.getElementById(gridId);
        var volumeQuota = grid.rows[rowIndex].cells[2].innerText;
        alert(volumeQuota);
        var coef = grid.rows[rowIndex].cells[5].childNodes.item(1).value;
        alert(coef);
        var prevSites = grid.rows[rowIndex].cells[4].innerText;;
        grid.rows[rowIndex].cells[6].childNodes.item(1).value = parseFloat(coef) * (parseFloat(volumeQuota) - parseFloat(prevSites));
        grid.rows[rowIndex].cells[7].childNodes.item(1).value = price;

    }

在这后面的代码中,我是如何添加它的。

         if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TextBox t1 = (TextBox)e.Row.FindControl("p98Margin1");
            t1.Attributes.Add("onkeyup",
                 string.Format("javascript:margin1('{0}', {1}, {2})", e.Row.RowIndex + 2,       a98.Text , GridView1.ClientID));

当我在 JavaScript 函数中发出警报Gridview1.clientId时,我得到了[objectHTMLTableElement]

4

2 回答 2

1

用这个

   t1.Attributes.Add("onkeyup",
             string.Format("javascript:margin1('{0}', '{1}', '{2})'", e.Row.RowIndex + 2,       a98.Text , GridView1.ClientID));

我认为这应该有效。
我认为该值应该用单引号括起来'

于 2013-01-14T06:26:36.150 回答
0

就像你说的那样,你把你的网格放在一个多视图中,一切都停止了,这意味着你的网格视图已经被掩埋了,你需要进一步钻取以暴露它。

做这个

 GridView myGridView=(GridView)(MultiView1.FindControl("GridView1"));

现在你已经找到了它,优雅地引用了它的 ID

   if (e.Row.RowType == DataControlRowType.DataRow)
    {
        TextBox t1 = (TextBox)e.Row.FindControl("p98Margin1");
        t1.Attributes.Add("onkeyup",
             string.Format("javascript:margin1('{0}', {1}, {2})", e.Row.RowIndex + 2,       a98.Text ,myGridView.ClientID));
   }

希望这可以帮助。

于 2013-01-14T08:27:04.820 回答