2017-08-24 55 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)); 
        }); 
       });