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
Basic Java Script Examples
Posted by
Rajesh Rolen
at
Tuesday, January 5, 2010
Labels: ASP.NET , GridView , java script
0 comments:
Post a Comment