Thursday, November 1, 2012

Retrieving top 10 records from Data Table using LINQ in ASP.NET

The below code will retrieve top 10 records from the data table.

DataTable1.AsEnumerable().Take(10);


Note: Add using System.Linq on the top.


If intellesense is not showing up, add reference to System.Core


We can copy these records to another data table as below


DataTable1.AsEnumerable().Take(10).CopyToDataTable();


Happy coding…

How to truncate text while data binding

How to truncate text in a label control to allow maximum number of characters. I would like to avoid using code behind because the label is in a repeater.

<%
   1: # Eval("EventDate").ToString().Substring(startIndex, Length of string)
%>


Happy coding…

Tuesday, September 18, 2012

How to find last day of month in C#

 

Below is the code for retrieving last day (max days) in a month.

System.DateTime.DaysInMonth(int year, int month)


Happy coding…