ASP.NET – DataSet Filter using Multiple Column Values

  • by
ASP.NET DataSet Filter - Date Filter Output Snapshot 03

ASP.NET DataSet Filter using Multiple Column Values:

Filtering ASP.NET DataSet values at runtime can prevent multiple trips or calls to your Database which improves your web application’s response time and it performs much better. We can filter ASP.NET DataSet using single Column values, multiple column values and also using two dates to view DataSet according to our need.  I have already discussed about filtering ASP.NET DataTable for similar results. Below are the syntax and code usage for filtering ASP.NET DataSet using Multiple column values.

My Database Table :

ASP.NET DataTable Filter - Database Snapshot 01

Syntax for ASP.NET DataSet Filter by multiple Column Values : 

dataSetName.Tables[0].DefaultView.RowFilter = "ColumnName ='YourDataToFilter' and SecondColumnName ='YourDataToFilter'";
dataGrid.DataSource = (dataSetName.Tables[0].DefaultView).ToTable();
dataGrid.DataBind();

Usage :

protected void Page_Load(object sender, EventArgs e)
{
FillGrid();
}

public void FillGrid()
{

SqlConnection con = new SqlConnection("Data Source=192.168.0.192;Initial Catalog=ParallelCodes;User ID=sa;Password=789");
SqlCommand cmd = new SqlCommand("Select * from tblCountries", con);
SqlDataAdapter sqlAdapter = new SqlDataAdapter(cmd);
DataSet dsCountries = new DataSet();
sqlAdapter.Fill(dsCountries, "tblCountries");
dsCountries.Tables[0].DefaultView.RowFilter = "Country ='India' and Id='1'";
dataGrid.DataSource = (dsCountries.Tables[0].DefaultView).ToTable();
dataGrid.DataBind();

sqlAdapter.Dispose();
cmd.Dispose();
con.Close();

}

Output :

ASP.NET DataSet Filter - Multiple Column Output Snapshot 2

ASP.NET DataSet Filter – Multiple Column Output Snapshot 2

 

Also see :

ASP.NET DataSet Filter.

ASP.NET DataSet Filter using Date values.

ASP.NET DataTable – Filtering Data using columns values.

ASP.NET DataTable – Filtering Data using Multiple column values.

ASP.NET DataTable – Filtering Data using Date values.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.