ObjList.ClassList.ForEach(x => x.Id =0); // It will change all Id's to 0
Wednesday, July 29, 2015
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;
}
}
});
}
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;Wednesday, October 1, 2014
Popup using Jquery with Ajax
<style type="text/css">
#divPopUp {
display: none;
position: absolute;
min-width: 350px;
max-width: 700px;
padding: 10px;
background: #fff;
color: #000000 !important;
border: 1px solid #1a1a1a;
font-size: 90%;
min-width: 200px;
word-wrap: break-word;
}
</style>
$(function ()
{
var moveLeft = 20;
var moveDown = 20;
$(".className").hover(function (e) {
if (($('#ContentDetails').html() != '')) {
$('#divPopUp').show();
}
},
function () {
$('#divPopUp').hide();
});
$(".className").mouseleave(function (e) {
$(#divPopUp').hide();
});
$(".className").mousemove(function (e) {
$’"#divPopUp').css('top', e.pageY + moveDown).css('left', e.pageX + moveLeft).appendTo('body');
});
});
<div id="divPopUp">
<h2>Heading</h2>
<div id="ContentDetails" runat="server"></div>
</div>
Calculate Years and Months Between Dates Using C# and Javascript
C# Code
public string CalculateTenure(DateTime Hday, DateTime Cday)
{
int Years =
0; int Months
= 0;
if
((Cday.Year - Hday.Year) > 0 || (((Cday.Year - Hday.Year) == 0) &&
((Hday.Month < Cday.Month) || ((Hday.Month ==
Cday.Month) && (Hday.Day <= Cday.Day)))))
{
int
DaysInHdayMonth = DateTime.DaysInMonth(Hday.Year, Hday.Month);
int DaysRemain = Cday.Day + (DaysInHdayMonth - Hday.Day);
if (Cday.Month > Hday.Month)
{
Years
= Cday.Year - Hday.Year;
Months = Cday.Month - (Hday.Month + 1) + Math.Abs(DaysRemain /
DaysInHdayMonth);
}
else if (Cday.Month == Hday.Month)
{
if (Cday.Day >= Hday.Day)
{
Years
= Cday.Year - Hday.Year;
Months
= 0;
}
else
{
Years
= (Cday.Year - 1) - Hday.Year;
Months = 11;
}
}
else
{
Years
= (Cday.Year - 1) - Hday.Year;
Months = Cday.Month + (11 - Hday.Month) + Math.Abs(DaysRemain /
DaysInHdayMonth);
}
}
return Years + " Year(s)
" + Months + " Month(s)";
}
Javascript Code
function CalculateTenure(Hday, Cday) {
var Years = ''; var Months = '';
var HdayDate = new Date(Hday);
var CdayDate = new Date(Cday);
var HdayDateYear = HdayDate.getFullYear();
var HdayDateMonth = HdayDate.getMonth() + 1;
var HdayDateDay = HdayDate.getDate();
var CdayDateYear = CdayDate.getFullYear()
var CdayDateMonth = CdayDate.getMonth() + 1;
var CdayDateDay = CdayDate.getDate();
if ((CdayDateYear - HdayDateYear) > 0 || (((CdayDateYear
- HdayDateYear) == 0) && ((HdayDateMonth < CdayDateMonth) ||
((HdayDateMonth == CdayDateMonth) && (HdayDateDay <=
CdayDateDay)))))
{
var DaysInHdayMonth = new Date(HdayDateYear,
HdayDateMonth, 0).getDate();
var DaysRemain = CdayDateDay + (DaysInHdayMonth - HdayDateDay);
if (CdayDateMonth > HdayDateMonth)
{
Years
= CdayDateYear - HdayDateYear;
Months = CdayDateMonth - (HdayDateMonth + 1)
+ Math.floor(DaysRemain / DaysInHdayMonth);
}
else if (CdayDateMonth == HdayDateMonth)
{
if (CdayDateDay >=
HdayDateDay)
{
Years = CdayDateYear - HdayDateYear;
Months = 0;
}
else
{
Years
= (CdayDateYear - 1) - HdayDateYear;
Months = 11;
}
}
else
{
Years
= (CdayDateYear - 1) - HdayDateYear;
Months
= CdayDateMonth + (11 - HdayDateMonth) + Math.floor(DaysRemain / DaysInHdayMonth);
}
}
return Years + "
Year(s) " + Months + " Month(s)";
}
Checkbox foreach using Id in Jquery
$('input:checkbox[id^="CheckboxId"]').each(function(){
if(this.checked)
{
// Do Actions
}
});
$("#GridviewId
input:checkbox[id$='CheckboxId']").each(function(){
if(this.checked)
{
// Do Actions
}
});
Subscribe to:
Comments (Atom)