DotNet Academy of Rajesh Rolen

Solutions by Rajesh Rolen

Basic Java Script Examples


lets we have a gridview as shown in pic. now we want have got rates of room and we want to select quantity in dropdownlist and on that basis we want to calculate total in last column of gridview. and then grand total in label below gridview.
then below javascript will help u out:





< script language="javascript" type="text/javascript" >
function ShowTotalPrices(selectbox) {

// var selectedStatus = dropDown.value;
//alert(selectedStatus);
var parentTr = selectbox.parentNode.parentNode;
var secondCellVal = parseInt ( parentTr.cells[4].innerText , 10 );
var comboVal = parseInt ( selectbox.value , 10 );

parentTr.cells[7].innerText = secondCellVal * comboVal;
ManipulateGrid();
}

function ManipulateGrid()
{
var gvDrv = document.getElementById("< %= GridView1.ClientID % >");
var gt=0.0;
for (i=1; i< gvDrv.rows.length; i++)
{
var cell = gvDrv.rows[i].cells;
var valold = cell[7].innerHTML;
var val = 0.0;
if(isNaN(parseFloat(valold)))
{
val= 0.0;
}
else
{
val = parseFloat(valold);
}

gt = parseFloat (gt) + val;
}
document.getElementById("lblgtamount").innerText=gt;
//lbl.Text = gt;
//alert(gt);
}

< /script >



in codding file write below code:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim ddlroombook As DropDownList = CType(e.Row.FindControl("ddlbookroom"), DropDownList)
Dim availablerooms As Integer = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "NumberOfUnits"))
ddlroombook.Attributes.Add("onchange", "javascript:ShowTotalPrices(this);")
Dim i As Integer
For i = 0 To availablerooms
ddlroombook.Items.Add(i)
Next
End If
End Sub

0 comments:

Post a Comment

About this blog

Blog Archive

My Blog List

Advertise On This Site

Site Info

Advertise on this Site

To advertise on this site please mail on RajeshRolen@gmail.com

Information Source

About

Pages

Dot Net Academy

Advertis in This Area of Site

Powered by Blogger.

Followers

Blog Archive

Search This Blog