2014年7月13日 星期日

[RESOLVED] Gridview - need to update other columns when textbox is changed


Hi,


I have an order form that uses a gridview control to display the products that can be selected by the user. I have a textbox for the quantity being ordered. When the quantity is changed I want to update the extended amount and the totals for the order. I
have tried to add the TextChanged event but it doesn't trigger the event. I have tried a javascript funtion and a C# function and neither works.


I have posted the gridview code...





































Thanks for the help!!


Gary





post ur C# code. or else u post ur calculation part.



This example uses a Label for the Price and Total, and a TextBox for the Quantity.  There is jQuery to calculate the Total.  Notice that the function is fired by the TextBox OnChange event.  Here is nice article on how to do this:

http://aspsnippets.com/Articles/Calculate-Row-Total-and-Grand-Total-in-ASPNet-GridView-using-jQuery.aspx


The ASPX Code:





OnChange="javascript:totalCalc();">



jQuery:


$(function totalCalc() {});
$("[id*=txtQuantity]").live("change", function () {
if (isNaN(parseInt($(this).val()))) {
$(this).val('0');
} else {
$(this).val(parseInt($(this).val()).toString());
}
});
$("[id*=txtQuantity]").live("keyup", function () {
if (!jQuery.trim($(this).val()) == '') {
if (!isNaN(parseFloat($(this).val()))) {
var row = $(this).closest("tr");
$("[id*=lblTotal]", row).html(parseFloat($("[id*=lblPrice]", row).html()) * parseFloat($(this).val()));
}
} else {
$(this).val('');
}
});


 


 



Hi,


Set AutoPostBack=true for TextBox.


You will get TextboxChange event to be fired only when you set AutoPostBack to true.


If you have placed your gridview in UpdatePanel Postback will be asynchronous.


Hope this helps!


沒有留言:

張貼留言