我有一個網格視圖,我想用JavaScript來計算在文本框中輸入的值。如何從視圖中獲取用於網格視圖的客戶端ID以便在javascript中使用
我在onrowcreated
函數的文本框中添加了onkeyup
,它工作正常。
然後我把gridview放在一個multiview
,它停止工作。
這是我的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]
感謝它的工作,但像這樣margin1('{0}','{1}','{2}')「, – user410911
,非常歡迎您:) –