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:
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;
}
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.
精彩评论