Wednesday 19 August 2015

numeric textbox validation using jquery

#errmsg
{
color: red;
}

-------------------------------------

Number : <input type="text" name="quantity" id="quantity" />&nbsp;<span id="errmsg"></span>
-------------------------------------


$(document).ready(function () {
  //called when key is pressed in textbox
  $("#quantity").keypress(function (e) {
     //if the letter is not digit then display error and don't type anything
     if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
        //display error message
        $("#errmsg").html("Digits Only").show().fadeOut("slow");
               return false;
    }
   });
});

Thursday 13 August 2015

gridview column total in footer row as per checkbox selection using jquery

<script type="text/javascript">
    $(function() {
        //event handler to the checkbox selection change event
        $("input[type=checkbox]").change(function() {
            //variables to store the total price of selected rows
            //and to hold the reference to the current checkbox control
            var totalPrice = 0, ctlPrice;
            //iterate through all the rows of the gridview
            $('#gvProducts tr').each(function() {
                //if the checkbox in that rows is checked, add price to our total proce
                if ($(this).find('input:checkbox').attr("checked")) {
                    ctlPrice = $(this).find('[id$= lblamount]');
                    //since it is a currency column, we need to remove the $ sign and then convert it
                    //to a number before adding it to the total
                    totalPrice += parseFloat(ctlPrice.text().replace(/[^\d\.]/g, ''));
                }
            });
            //finally set the total price (rounded to 2 decimals) to the total paragraph control.
            $('#lblTotal').text("$ " + totalPrice.toFixed(2));               
        });
    });
</script>

--------------------------------------------------------------

<asp:TemplateField>
                                            <HeaderTemplate>
                                                <asp:CheckBox runat="server" ID="chkHeader" Checked="true" OnCheckedChanged="chkHeader_CheckedChanged"
                                                    AutoPostBack="true" />
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chk_shouldinsert" runat="server" Checked="true" ClientIDMode="Static"
                                                    CssClass="chkClass" />
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:Label ID="lbltxttotal" runat="server" Text="Total" />
                                            </FooterTemplate>
                                        </asp:TemplateField>
--------------------------------------------------------------

 <asp:TemplateField HeaderText="CheckUp Amount">
                                            <ItemTemplate>
                                                <asp:Label ID="lblamount" runat="server" Text='<%# Eval("CD_SELLING_PRICE") %>' ClientIDMode="Static" />
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:Label ID="lblTotal" runat="server" ClientIDMode="Static" />
                                            </FooterTemplate>
                                        </asp:TemplateField>