我有一个gridview,在这些列中总共有几列,其中一个是复选框,你需要做的是获取最后一列的值并将其显示(如果有几个添加它们)到网格中你用复选框选择试试甚至CheckedChanged(低音代码),这个代码下面只有我0而不是歌曲或总和,我被告知我可以用java scribt但我不知道该怎么做
代码:
Dim Total As Decimal
For Each row As GridViewRow In Gvcobranzas.Rows
Dim check As CheckBox = DirectCast(row.FindControl("CheckBox1"), CheckBox)
If check.Checked = True Then
Dim x As Decimal = 0
If Decimal.TryParse(row.Cells(2).Text, x) Then
Total += CDec(row.Cells(2).Text)
End If
End If
Next
TxtMonto.Text = Total
答案 0 :(得分:0)
Ligro hacer con javascript
dejo el codigo
$(function() {
$("input[type=checkbox]").change(function() {
//variables to store the total price of selected rows
//and to hold the reference to the current checkbox control
var totalPrice = 0, ctlPrice;
//iterate through all the rows of the gridview
$('.Gvcobranzas tr').each(function() {
//if the checkbox in that rows is checked, add price to our total proce
if ($(this).find('input:checkbox').attr("checked")) {
ctlPrice = $(this).find('[id$= Label3]');
//since it is a currency column, we need to remove the $ sign and then convert it
//to a number before adding it to the total
totalPrice += parseFloat(ctlPrice.text().replace(/[^\d\.]/g, ''));
}
});
//finally set the total price (rounded to 2 decimals) to the total paragraph control.
$('.sum').text("$ " + totalPrice.toFixed(2));
});
});