how to calculated Gridview Calculation

Posted by Jayakumars under Regular Expressions on 8/3/2011 | Points: 10 | Views : 5680 | Status : [Member] [MVP] | Replies : 7
hi

i need how to calculate gridview textbox in gridview textbox change
event using javascript how will do this

my code like this but not fire


var gridView = document.getElementById('<%= Grd1.ClientID %>');
var selectedRowIndex = RecCtrl.parentNode.parentNode.rowIndex;
var txt1 = gridView.rows[parseInt(selectedRowIndex)].cells[0].children[0];
alert (txt1);


Mark as Answer if its helpful to you


Responses

Posted by: Sripriya on: 8/3/2011 [Member] Starter | Points: 25

Up
0
Down
hai,
http://www.codeproject.com/KB/webforms/DBCalculationGridView.aspx

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sripriya on: 8/3/2011 [Member] Starter | Points: 25

Up
0
Down
hai,
http://www.codeproject.com/KB/webforms/DBCalculationGridView.aspx

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 8/3/2011 [Member] Bronze | Points: 25

Up
0
Down

here is javascript function that calculate certain values on textbox textchanges event:

function calculateRate(obj, lbl)
{
var str1 = lbl.substring(0,lbl.lastIndexOf('_')+1);
var str = obj.id.substring(0,obj.id.lastIndexOf('_')+1);
var margin = document.getElementById(str + 'txtMargin').value;
var addition = document.getElementById(str + 'txtAddition').value;
var rwsp = document.getElementById(str + 'lblRwsp').innerHTML;
var rapo = document.getElementById(str + 'lblRapo').innerHTML;
var cts = document.getElementById(str + 'lblCts').innerHTML;
var totCts = document.getElementById(lbl).innerHTML;
var totQRate = document.getElementById(str1 + 'lblTotQuatRate').innerHTML;
var qrate = document.getElementById(str + 'lblQuatRate').innerHTML;
var amt = document.getElementById(str + 'lblAmt1').innerHTML;
var totAmt = document.getElementById('InsertQuotationControl1_hdTotAmt').value;
//document.getElementById(str1 + 'lblTotAmt1').innerHTML;

//alert(totAmt);
if(margin.length != 0 && margin != ' ')
margin = parseFloat(margin);
if(addition.length != 0 && addition != ' ')
addition = parseFloat(addition);
if(rwsp.length != 0 && rwsp != ' ')
rwsp = parseFloat(rwsp);
if(cts.length != 0 && cts != ' ')
cts = parseFloat(cts);
if(rapo.length != 0 && rapo != ' ')
rapo = parseFloat(rapo);
if(totCts.length != 0 && totCts != ' ')
totCts = parseFloat(totCts);
if(totQRate.length != 0 && totQRate != ' ')
totQRate = parseFloat(totQRate);
if(totAmt.length != 0 && totAmt != ' ')
totAmt = parseFloat(totAmt);
if(qrate.length != 0 && qrate != ' ')
qrate = parseFloat(qrate);
if(amt.length != 0 && amt != ' ')
amt = parseFloat(amt);

var val = roundnum(rwsp * (1 + (margin/100)),2) + addition;
totQRate = ((totQRate * totCts)-(qrate * cts) + (val * cts))/totCts;
totAmt = totAmt - amt + Math.round(val*cts);
document.getElementById(str + 'lblQuatRate').innerHTML = nearestround(val);
if(rapo != -1)
document.getElementById(str + 'lblRap').innerHTML = roundnum((1-(val/rapo))*100,1);
else
document.getElementById(str + 'lblRap').innerHTML = -1;

document.getElementById(str + 'lblAmt').innerHTML = Math.round(val*cts);
document.getElementById(str + 'lblAmt1').innerHTML = Math.round(val*cts);
document.getElementById(str1 + 'lblTotQuatRate').innerHTML = nearestround(totQRate);
document.getElementById(str1 + 'lblTotAmt').innerHTML = Math.round(totAmt);
document.getElementById('InsertQuotationControl1_hdTotAmt').value = Math.round(totAmt);
}

for this write RowDataBound event in grid:


and find textbox control for each row and register this javascript function in "onchange event
like:

Textbox txt = e.Row.FindControl("<your-Textbox-name>");
txt.Attributes.Add("onchange","return calculateRate(this,someOtherControlID)");

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 8/3/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Pls go thru this article

http://www.dotnetfunda.com/articles/article1182-calculate-running-total-in-a-grid-view-and-display-.aspx

Written by me will definitely help you


Thanks and Regards
Madhu

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 8/3/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
madhu good post but this is image file can u send the project in my email id i think thats helpful for me
my email id: kumaraspcode2009@gmail.com

Mark as Answer if its helpful to you

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 8/3/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Sure, I will do that for you.. some time today







Thanks and Regards
Madhu

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Avianshpawar on: 7/17/2012 [Member] Starter | Points: 25

Up
0
Down
Hey Madhu
very nice post.i hv tried but i m getting error so
plz send me your code on avinashpawar5@gmail.com

regards
avinash

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response