2017-08-24 53 views
0

我有一个gridview在这些列内总共有几列,其中一个是复选框你需要做的就是取最后一列的值并显示它(在case几个添加他们)到您选择的网格,复选框尝试甚至CheckedChanged(低音代码),这个代码下面只有我0,而不是歌曲或总和,我被告知,我可以用java scribt,但我不知道如何做到这一点一个gridview与复选框的文本框的总和值

代码:

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)); 
        }); 
       });