Wednesday, 27 November 2013

Bind Comma Separated string Values into Dropdown

 string str = "A,B,C,D,";
            //Declare a arraylist for getting comma separated string
            ArrayList arr = new ArrayList();
            //check wether the re is comma in the end of the string
            if (str.Trim().EndsWith(","))
            {
                str = str.Substring(0, str.Length - 1);
            }
            //split the comma separated string into arraylist
            arr.AddRange(str.Split(','));
            //loop through the arraylist items & add the item to Dropdownlist
            for (int i = 0; i < arr.Count; i++)
            {
                DropDownList1.Items.Insert(i, new ListItem(arr[i].ToString(), (i + 1).ToString()));
            }

Sunday, 24 November 2013

by entering percentage on textbox it will calculate grid column percentage and add that percentage amount with that column amount and stored it to another column for every line item of the grid

function fcnDistribution() {
     // ClearValues();
     var gridrowLength = $("span[id$=lblSCAmount]").length;
     var Percentage = $("[id$='txtServiceChargePerc']").val();
     // alert("Percentage" + Percentage);
     $("span[id$=lblSCAmount]").each(function () {
         var id = $(this).attr('id');
         var rowId = id.substr(id.length - 17).substr(0, 5);
         var ScAmount = Filtervalue($(this));
         // alert("SC Amount" + ScAmount);
         // alert(parseFloat(ScAmount) +"\r\n"+ parseFloat(Percentage.replace("%", '')))
         //if()
         {

             var perCAmount = parseFloat((parseFloat(ScAmount) * parseFloat(Percentage.replace("%", ''))) / 100);
             // alert("perCAmount" + perCAmount);
             var totalamt = parseFloat(perCAmount) + parseFloat(ScAmount);
             //alert("total" + totalamt);
         }
         var txtChargeAmountId = $("[id$=" + rowId + "_txtChargeAmount]");
         //alert("txtAmountId" + txtChargeAmountId.val());
         var ChargeAmt = "$" + parseFloat(totalamt, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString();
         txtChargeAmountId.val(ChargeAmt);
     });
 }


   function ValidatePercent() {

        var ServiceChargePerc = $("[id$='txtServiceChargePerc']");

        $(ServiceChargePerc).keydown(function (event) {
           // onlyNumbers(event);

            $(ServiceChargePerc).focusout(function (event) {
                var percent = $(ServiceChargePerc).val().replace("$", " ");

                if (percent.indexOf('%') == -1 && $(ServiceChargePerc).val().length != 0)
                    $(ServiceChargePerc).val(parseFloat(percent).toFixed(2) + "%");

            });
        });




 function Filtervalue(input) {
     var Output = input.text();
     // alert(1);
     Output = Output.replace("$", ''); //Replace  "$"(Doller) with empty string    
     Output = Output.replace(/,/g, '');   //Replace n no of ","(camas) with empty string
     return Output;
 }


------------ textbox focus out event call function
function MouseOutvalidationReceiptHeader() {

     var txtAmountReceipt = $("[id$='txtServiceChargePerc']");


     txtAmountReceipt.focusout(function () {
         if ($.trim(txtAmountReceipt.val()) != "") {
              fcnDistribution();
             ValidatePercent();
         }
     });
 }

----------call method on postback and ready

 $(document).ready(function () {
        ValidatePercent();
        WOChargesFocusOutValid();
        MouseOutvalidationReceiptHeader();
 
    });

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(function (s, e) {
        ValidatePercent();
        MouseOutvalidationReceiptHeader();
        $('form').dirtyForms();

    });

Jquery for Grid textbox validation with required field


    function ValidateElement(element) {

        if ($(element).val() == '') {
            $(element).css("border", "1px solid red");
        }

        $(element).hover(function () {
            if ($(element).val() == '') {
           
                qtipPopup(element, "Required Field");
            }
        },
          function () {
              if ($(element).data("qtip")) $(element).qtip("destroy");
          });

        $(element).focusout(function () {
            if ($(element).val() != '') {
                $(element).css("border", "");
            }
            else {
                $(element).css("border", "1px solid red");
            }
        });

    }

    function qtipPopup(element, message) {
        $.fn.qtip.zindex = "999";
        if ($(element).data("qtip")) $(element).qtip("destroy");
        $(element).css("border", "1px solid red");
        $(element).qtip({
            overwrite: false, content: message,
            position: { my: 'bottomLeft', at: 'leftTop' },
            show: { event: 'focus' },
            hide: { event: 'focusout' },
            style: { classes: 'ui-tooltip-green', name: 'dark' }
        });
    }

    function GridTextValidation() {

        var gridValid = true;
        var loopStart = ($("[id$='grdWorkOrderCharges']").find('tr').length > 9) ? 0 : 1;
        for (var i = loopStart; i < $("[id$='grdWorkOrderCharges']").find('tr').length; i++) {

            var rowData1 = $("[id$='grdWorkOrderCharges']").find('tr')[i];

            var ChargeAccountInfo = $(rowData1).find('input[id$=txtChargeAccount]');

            if ($(ChargeAccountInfo) != null) {

                if ($(ChargeAccountInfo).val().length > 0) {
                    if ($(ChargeAccountInfo).data("qtip"))
                        $(ChargeAccountInfo).qtip("destroy");
                }
                else {
                    ValidateElement($(ChargeAccountInfo));
                    gridValid = false;

                }
            }

        }
        return gridValid;
    }

Grid total column values calculate and display into the label

   function AddTotal() {
        var tot = 0.00;
        $("[id$='txtChargeAmount']").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);
    }