February 2010 Entries

Create IEnumerable<T> with one line in LINQ

Pretty straight-forward, but a useful snippet of code nonetheless. Given this class: public class AggregateContent { public string Title { get; set; } public string Description { get; set; } public AggregateContent(string Header, string Content) { Title = Header; Description = Content; } } You can use line to create an IEnumerable<AggregateCon... like this: IEnumerable<AggregateCon... a = LastNNewsItems.Select(p => new AggregateContent(p.NewsTitle, p.HtmlContent)); Technorati Tags:...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

jQuery: Get value of checked checkboxes by name | className

Think this one speaks for itself :) //Get via name attribute. Would be better if you added form ID to selector var checkBoxes = $("input[name=" + checkBoxName + "]"); //Need to use each or you'll only get the first match $.each(checkBoxes, function() { if ($(this).attr('checked')){ //do stuff } }); //Get via class name. Would be better if you added form ID to selector var checkBoxes = $('.' + checkBoxClass); $.each(checkBoxes, function() { if ($(this).attr('checked')){ //do stuff } });...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Twitter