开发者

Gridview data update on each textbox keystoke

Gridview data update on each textbox keys开发者_Go百科toke


It is not totally clear what you'd like to do, but assuming you want to update a running total or other such scriptable update:

  1. Create a Javascript function to do the totaling from the controls. This will require some processing of the ASP.Net control names.

    function UpdateTotal(txtYourTextBoxId) { // Get the value from the textbox, in this case a Quantity
    var Qty = document.getElementById(txtYourTextBoxId).value;

    // Do stuff with this control and/or all controls on page
    // foreach, etc.
    
    
    // change the total at the bottom of the grid
    document.getElementById("ctl00_lblTotal").innerHTML = Qty;
    

    }

  2. In your code behind, add an "OnChange" attribute whenever the textbox value changes. This is done in the RowDataBound event:

    protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType != DataControlRowType.DataRow) return; TextBox txtYourTextBox= (TextBox)e.Row.FindControl("txtYourTextBox"); txtYourTextBox.Attributes["onchange"] = "UpdateTotal(this.id)"; }

Thus whenever there is an OnChange event from a textbox, the javascript function is fired.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜