Click here to Skip to main content
15,889,499 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
I am making a shopping cart website in which i want to filter records by products name and price. so can you please help me , as i do not have any idea about it.
Posted
Comments
Christian Amado 25-Mar-14 10:53am    
What object(Class, DataTable, DataSet, other) are you using? What did you try? We cannot do your homework for you.
Herman<T>.Instance 25-Mar-14 11:37am    
What efforts did you make? ANy code to show the problem?

If you are using queries, filter data at the query level. This would be the most optimized filter as you would send less data over the wire.
 
Share this answer
 
There are two approaches

1. Make query to db each time the search text box changes using ajax, and apply the filter in db using like '%searchstring%'

OR

2. Get all data to UI/Service/Business layer using EF/SP/DataReader ... and filter data using .Contains clause in LINQ
 
Share this answer
 
v2
When you say records, I am assuming Database table record selection here. Have you checked your SQL Queries (Where clause, Joins etc)??
 
Share this answer
 
try this

C#
if ( ddlsearchby.SelectedItem.Text == "All")
 {
 DataTable dt = new DataTable();
 SqlDataAdapter da = new SqlDataAdapter("Select * from tbl ", con);
 SqlCommandBuilder cmd = new SqlCommandBuilder(da);
 da.Fill(dt);
 dgvitemDetails.DataSource = dt;
 }
 else
 {
 DataTable dt = new DataTable();
 SqlDataAdapter da = new SqlDataAdapter("Select * from tbl where " +  ddlsearchby.SelectedItem.text + " = '" + txtSearch.Text + "'", con);
 SqlCommandBuilder cmd = new SqlCommandBuilder(da);
 da.Fill(dt);
 dgvitemDetails.DataSource = dt;
}


complete example then visit link

http://hightechnology.in/how-to-filter-gridview-records-with-dropdownlist-selection/[^]
 
Share this answer
 
v4
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900