Skip to main content
ASP.NET DataSet Filter - Date Filter Output Snapshot 03

ASP.NET – DataTable Filter by Date

ASP.NET – DataTable Filter by Date:

Filtering Data of ASP.NET DataTable can avoid round trips to your database multiple times and also increases your Web application’s response time. Filtering the values of ASP.NET DataTable can be achieved using RowFilter property where in we can make use of “where” clause to filter our DataTable based on Column values. Filtering can also  be done for multiple column values and also for Date values using the ‘between’ keyword. Below are the Syntax and usage of the Syntax respectively. ASP.NET datatable filter :

My Database table :  

ASP.NET DataTable Filter - Database Snapshot 01

Syntax for filtering ASP.NET DataTable using Date value :

DataView dv = dataTableId.DefaultView;
dv.RowFilter = "DateColumnName  >='FromDate' and DateColumnName  <='ToDate'";
dataGridId.DataSource = dv;

Usage :

protected void Page_Load(object sender, EventArgs e)

public void FillGrid()
SqlConnection con = new SqlConnection("Data Source=;Initial Catalog=ParallelCodes;User         ID=sa;Password=789");
SqlCommand cmd = new SqlCommand("Select * from tblCountries", con);
SqlDataAdapter sqlAdapter = new SqlDataAdapter(cmd);
DataTable dtCountries = new DataTable();

DataView dv = dtCountries.DefaultView;
dv.RowFilter = "OnDate >= '2018-02-01 00:00:00.000' and OnDate <='2018-02-05 23:59:59.000'";
dataGrid.DataSource = dv;


Output :

ASP.NET DataTable Filter - Date Filter Output Snapshot 03
ASP.NET DataTable Filter – Date Filter Output Snapshot 03

Also see :
ASP.NET DataTable filter
ASP.NET DataTable filter using Multiple Columns – Filtering data of DataTable in ASP.NET.