如何在网格视图的SelectedIndexChanging上应用javascript

时间:2012-04-26 04:01:04

标签: asp.net gridview

我已经使用了一个javascript,我正在使用它 onblur 在gridview中的文本框事件。当我执行gridview的 SelectedIndexChanging 时,我会触发相同的脚本。这是我的剧本

<script type="text/javascript">
function total(txtQuantity, txtRate, txtAmount) {
    var col1;
    var totalcol1 = 0;
    var weight = document.getElementById(txtQuantity).value;
    var rate = document.getElementById(txtRate).value;
    var tot = weight * rate;
    document.getElementById(txtAmount).value = tot.toFixed(2).toString();
    var grid = document.getElementById('<%=grdInvoice.ClientID %>');


    for (i = 0; i < grid.rows.length; i++) {
        col1 = grid.rows[i].cells[4];
        //col2 = grid.rows[i].cells[1];

        for (j = 0; j < col1.childNodes.length; j++) {
            if (col1.childNodes[j].type == "text") {
                if (!isNaN(col1.childNodes[j].value) && col1.childNodes[j].value != "") {
                    totalcol1 += parseInt(col1.childNodes[j].value)
                }
            }
        }
    }
    document.getElementById('<%= lblTotal.ClientID %>').innerHTML = totalcol1.toFixed(2).toString();
    document.getElementById('<%=lblResultbalance.ClientID%>').innerHTML = totalcol1.toFixed(2).toString();
    document.getElementById('<%=TextBox1.ClientID%>').value = totalcol1.toFixed(2).toString();
}

有人可以帮助我

1 个答案:

答案 0 :(得分:0)

在您的活动中尝试此操作

ScriptManager.RegisterStartupScript(this, GetType(), "script", "total('" + txt1.ClientID + "','" + txt2.ClientID + "','" + txt3.ClientID + "')", true);