Hello Sir,
I'm trying to calculate the total hours of an employee in gridview.Below is the code which im using , but in this, im able to add the new value with the value generated from onrowdatabound. So here i want the new value which is entered into the textbox to be displayed outside.
<script type="text/javascript">
$(function () {
$("[id*=meal_mon1]").val("0");
});
$("body").on("change keyup", "[id*=meal_mon1]", function () {
var quantity = parseFloat($.trim($(this).val()));
if (isNaN(quantity)) {
quantity = 0;
}
$(this).val(quantity);
var row = $(this).closest("tr");
$("[id*=lblTotal1]", row).html(parseFloat($(".price", row).html()) + parseFloat($(this).val()));
//Calculate and update Grand Total.
var grandTotal12 = 0;
$("[id*=lblTotal1]").each(function () {
grandTotal12 =grandTotal12 + parseFloat($(this).html());
});
$("[id*=lblGrandTotal1").html(grandTotal12.toString());
});
</script>
<asp:GridView runat="server" Width="900px" AutoGenerateColumns="false" AllowPaging="true" ID="gvEmployees" OnRowDataBound="gvEmployees_RowDataBound1">
<Columns>
<asp:BoundField DataField="date1" HeaderText="Monday" DataFormatString="{0:MM/dd/yyyy}" ItemStyle-Width="47px" ItemStyle-Wrap="false"/>
<asp:BoundField DataField="from_time" HeaderText="Start Time" ItemStyle-Width="47px" ItemStyle-Wrap="false"/>
<asp:BoundField DataField="to_time" HeaderText="To Time" ItemStyle-Width="47px" ItemStyle-Wrap="false"/>
<asp:BoundField DataField="time_per_day" ItemStyle-CssClass="price" HeaderText="Normal Hours" ItemStyle-Width="47px" ItemStyle-Wrap="false"/>
<asp:BoundField DataField="" HeaderText="Public Hours" ItemStyle-Width="75px" ItemStyle-Wrap="false"/>
<asp:BoundField DataField="" HeaderText="Weekend Hours" ItemStyle-Width="55px" ItemStyle-Wrap="false"/>
<asp:TemplateField HeaderText="Meal Time" ItemStyle-Width="47px" ItemStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="meal_mon1" runat="server" Width="20px" BorderStyle="None"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total" ItemStyle-Width="67px" ItemStyle-Wrap="false">
<ItemTemplate>
<asp:Label ID="lblTotal1" runat="server" />
</ItemTemplate>
<FooterTemplate>
<b>Grand Total: </b>
<asp:Label ID="lblGrandTotal" runat="server" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Using the above code its displaying the total hours where i want only the new value entered into the textbox to be displayed.
Please help me
Thanks