Wednesday, July 29, 2015

How to change the name of the button using Jquery

<input type='button' value='Add' id='btnAddProfile'>
$("#btnAddProfile").attr('value', 'Save'); //versions older than 1.6

<input type='button' value='Add' id='btnAddProfile'>
$("#btnAddProfile").prop('value', 'Save'); //versions newer than 1.6

<button id='btnAddProfile' type='button'>Add</button>
$("#btnAddProfile").html('Save');

How to Make Checkbox checked using Jquery

$('input:checkbox[id=2]').prop('checked', true);

How to change/modify values in list of list in C#

ObjList.ClassList.ForEach(x => x.Id =0); // It will change all Id's to 0

How to validate table column values as Row level

function ValidateTableTDInputValues() {
$('input').removeClass('error');
       $('span.mandatory').remove();
       var res = true;
       this.$('.ClassName1, .ClassName2').each(function () {
       var value = '';
       value = $(this).val();
       var tableRow = $(this).parent().parent();
       if (value != "") {
       var txtBoxOneInput = tableRow.find("td:nth-child(1) input[type=text]");
       var txtBoxOneValue = txtBoxOneInput.val();
       var txtBoxTwoInput = tableRow.find("td:nth-child(2) input[type=text]");
var txtBoxTwoValue = txtBoxTwoInput.val();
       var txtBoxThreeInput = tableRow.find("td:nth-child(3) input[type=text]");
       var txtBoxThreeValue = txtBoxThreeInput.val();
       var txtBoxFourInput = tableRow.find("td:nth-child(4) input[type=text]");
       var txtBoxFourValue = txtBoxFourInput.val();

       if (!$(txtBoxOneInput).hasClass('error') && $.trim(txtBoxOneValue) == '') {
       $(txtBoxOneInput).addClass('error').after('<span class="mandatory">*</span>');
res = false;
       }
      
if (!$(txtBoxTwoInput).hasClass('error') && $.trim(txtBoxTwoValue) == '') {
       $(txtBoxTwoInput).addClass('error').after('<span class="mandatory">*</span>');
res = false;
}
      
if (!$(txtBoxThreeInput).hasClass('error') && $.trim(txtBoxThreeValue) == '') {
       $(txtBoxThreeInput).addClass('error').after('<span class="mandatory">*</span>');
res = false;
       }
if (!$(txtBoxFourInput).hasClass('error') && $.trim(txtBoxFourValue) == '') {
       $(txtBoxFourInput).addClass('error').after('<span class="mandatory">*</span>');
res = false;
}
    }
});
 if (res) { return true; } else { return false; }
}

How to convert DbContext list into our local class List


List<Tempclass> objList = new List<Tempclass>();
var objValues = DbContext.Values.Where(val => (val.Id == Id) && (val.IsObsolute == (Boolean?)false));

if (objValues != null && objValues.Any())
{
    objList = (from Value res in objValues
              select new Tempclass()
              {
   Id = res.Id,
                Name = res.Name,
               Age = res.Age,
               Sex = res.Sex
              }).ToList();
 }
 return objList;