Friday, 25 October 2013

Gridview row having button and button click event enable disabling grid view textboxes

 protected void btnExpenseAccount_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            GridViewRow grv = (GridViewRow)btn.NamingContainer;
            int index = grv.RowIndex;
            TextBox txtExpenseAccount = (TextBox)grvVendorProperties.Rows[index].FindControl("txtExpenseAccount");
            TextBox txtInitialBalance = (TextBox)grvVendorProperties.Rows[index].FindControl("txtInitialBalance");
            Button btnExpenseAccount = (Button)grvVendorProperties.Rows[index].FindControl("btnExpenseAccount");
            TextBox txtEffectiveDate = (TextBox)grvVendorProperties.Rows[index].FindControl("txtEffectiveDate");
            TextBox txtReceiptAccount = (TextBox)grvVendorProperties.Rows[index].FindControl("txtReceiptAccount");
            Button btnReceiptAccount = (Button)grvVendorProperties.Rows[index].FindControl("btnReceiptAccount");
            txtExpenseAccount.Enabled = true;
            txtInitialBalance.Enabled = true;
            btnExpenseAccount.Enabled = true;
            txtEffectiveDate.Enabled = true;
            txtReceiptAccount.Enabled = true;
            btnReceiptAccount.Enabled = true;

 }

Thursday, 3 October 2013

MaskedEdit "backspace" and delete problem with safari and chrome -- here's the fix!

the fix is easy. in the current source code of MaskedEditBehavior.js about line 890 you have this:


if (Sys.Browser.agent == Sys.Browser.InternetExplorer || evt.type == "keypress")  
    {
        if (scanCode == 8) // BackSpace
the code should be
if (Sys.Browser.agent == Sys.Browser.InternetExplorer || evt.type == "keydown")  
    {
        if (scanCode == 8) // BackSpace
     ...

Saturday, 21 September 2013

asp.net Time textbox

 aspx page code.

<script type="text/javascript">

    // Time validation for Scheduled Time
    function ValidateScheduledTimeFormatSC() {

        var msg = "";
        var txtTimeValue = $("[id*='txtSchTime']").val();
        regularExpression = /^(\d{1,2}):(\d{2})(:00)?(\s)?([AP]M|[ap]m)?$/;
        try {
            if (txtTimeValue != '') {
                if (arrregularExpressions = txtTimeValue.match(regularExpression)) {
                    if (arrregularExpressions[4]) {
                        // check for am/pm. This is 12hours time format check
                        if (arrregularExpressions[1] < 1 || arrregularExpressions[1] > 12) {
                            msg = "Error: enter valid hours. Either 12hours with am/pm here am/pm is optional(or) 24hours time format: ";
                        }
                    }
                    else {
                        // This is 24hours time format check
                        if (arrregularExpressions[1] > 23) {
                            msg = "Error: enter valid hours. Either 12hours with am/pm (or) 24hours time format: ";
                        }
                    }
                    if (!msg && arrregularExpressions[2] > 59) {
                        msg = "Error: enter valid minutes: " + arrregularExpressions[2];
                    }
                }
                else {
                    msg = "Error: enter valid time format. Example: 10:15am or 19:20: ";
                }
            }
            else {
                $("#divSchTimeFormatError").css("display", "block");              
           
            }
            if (msg != "" && txtTimeValue != "__:__ AM" && txtTimeValue != "__:__ PM") {
                $("#divSchTimeFormatError").css("display", "block");              
               return false;
            }
            else {
                if (msg != "") {
                    $("#divSchTimeFormatError").css("display", "none");                  
                    return true;
                }
                else {
                    $("#divSchTimeFormatError").css("display", "none");                  
                    return true;
                }
            }
         
        }
        catch (ex) { alert(ex); }

    }
</script>




 <div class="fieldset" runat="server" id="divScheduledTime">
                    <label>
                        <span id="span2" runat="server">Scheduled Time </span>
                        <asp:Label ID="lblSchTime" Visible="false" runat="server"></asp:Label>
                    </label>                  
                   <div id="divSchTimeFormatError" class="tooltip" style="margin-left: 410px;">
                        <span class="pointer"></span>Scheduled Time is not valid
                    </div>          

                    <div class="margin_bottom_5">                      
                        <asp:TextBox ID="txtSchTime" runat="server" ClientIDMode="Static" class="inputTextTime"
                            onblur="ValidateScheduledTimeFormatSC();"></asp:TextBox>
                        <Ajax:MaskedEditExtender ID="MaskedSchTime" runat="server" AcceptAMPM="true" Mask="99:99"
                            AcceptNegative="None" Enabled="True" MaskType="Time" TargetControlID="txtSchTime" ClearTextOnInvalid="true"  >
                        </Ajax:MaskedEditExtender>
                    </div>
                </div>



Generic list sum Amount column value

 decimal sum = listServiceCall.Select(f => Convert.ToDecimal((f.AMOUNT.ToString().IndexOf("$") != -1) ? f.AMOUNT.Replace("$", "") : (f.AMOUNT != "") ? f.AMOUNT : "0")).Sum();

Grid view calculate amount column total to grid footer label

 Example:-1  best example working fine

  function AddTotal() {    
        var tot = 0.00;
        $("[id$='vtxtAmount']").each(function () {
            var sum = $(this).val();
           // alert('sum' + sum);
            sum = sum.replace("$", ''); //Replace  "$"(Doller) with empty string    
            sum = sum.replace(/,/g, '');   //Replace n no of ","(camas) with empty string    

            if (isNaN(sum)) {
                //alert(sum + ' is not a number');
            }
            else {
                if (sum == "") {
                    sum = 0;
                }
                tot += parseFloat(sum);
            }
        });
        //Display the total sum of Values to "txtAmountReceipt" control
        var Total = '$' + tot.toFixed(2);
        $("[id$='lblTotalAmount']").text(Total);
        $("[id$='hdnTotalAmount']").val(Total);
    }
   
------------------------------------------------------------------------
Example:2   not best example some time its not work

 function AddTotal() {
        var TotalDebit = 0;
        $("[id$='vtxtAmount']").each(function () {
            var data = $(this).val();
            if (data != "" && data.indexOf("$") !== -1) {
                data = data.substring(1);
            }
            var addValue = data;
            if (addValue != "") {
                if (isNaN(parseFloat(addValue))) {
                }
                else {
                    TotalDebit = (parseFloat(TotalDebit) + parseFloat(addValue));
                }
            }
        });
        document.getElementById('lblTotalAmount').innerHTML = "$" + parseFloat(TotalDebit).toFixed(2);
            $("[id$='hdnTotalAmount']").val(document.getElementById('lblTotalAmount').innerHTML);
    $("[id$='lblTotalAmount']").text = "$" + parseFloat(TotalDebit).toFixed(2);
    $("[id$='hdnTotalAmount']").val($("[id$='lblTotalAmount']").text);
    }
-----------------------------------------------------------------------------------------------------------------