Click here to Skip to main content
14,668,434 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello!!!

I have a gridview. There is a checkbox column inside gridview. what i need is as soon as user clicks checkbox for any row value should be calculated and shown in a template field in the same row.
I dont need to do this on some button click event Outside gridview as i have done that what i want is it should be done inside gridview as soon as checkbox is checked.


thanks!!
Posted
Comments
dimpledevani 18-Jul-12 7:32am
   
use the checkedchange event of checkbox

Rate this:
Please Sign up or sign in to vote.

Solution 1

I suggest using javascript for this task (to prevent postback for each click)

give all your checkboxes an data-rowId attribute and each row the same id.
give all your textboxes a class (or other attribute) to know which ones to calculate.

Then add an event on all your checkboxes.

$('input[type="checkbox"]').on('click', function(){
   var rowId = $(this).attr('data-rowId');

   var sum = 0;
   $('#'+rowId+' input.calculateMe').each(function(){   
      var currentTextbox = $(this);
      var val = parseFloat(currentTextbox.val());
      sum += val;
   });

   $('#txtSumEveryting').val(sum);
});
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

hi,

you can do it in gridview itemdatabound event where you can find id of that record on checkbox click. and there you will have values for calculations and store in where you want.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100