开发者

Gridview data update on each textbox keystoke

开发者 https://www.devze.com 2023-01-16 16:20 出处:网络
Gridview data update on each textbox keys开发者_Go百科tokeIt is not totally clear what you\'d like to do, but assuming you want to update a running total or other such scriptable update:

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

精彩评论

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