Friday, September 10, 2010

Remove JSON object from array/list

JavaScript



Code

// list of objects where the 'number' property is unique
var _numbers = [{number: 4589, name: "lorem"}, {number: 2554, name: "ipsum"}, {number: 9880, name: "siamet"}];

// find index for the object we want to remove from the list
var idx = -1;
var num = 9880;
for (var i = 0; i < _numbers.length; i++) {
if (num == _numbers[i].number) {
idx = i;
break;
}
}
// remove object from the list
if (idx != -1)
_numbers.splice(idx, 1);

Tuesday, September 7, 2010

Helper method: Markup + Code behind

Markup (aspx, asmx)



Code behind (C#)



end

Wednesday, September 1, 2010

String.Format + DataBinder aspx

String.Format (asp.net aspx page)