Click here to Skip to main content
15,943,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I'm developing a page which when loads is populated with a grid view which contains data. Along with this the user is presented with drop down list to be able to filter the data. Below is an example of some code.

protected void ddlSite_SelectedIndexChanged(object sender, EventArgs e)
            DataTable dtWorksOrderSummary = new DataTable();
            ReportBC reportBC = new ReportBC();

            DataSet ds = new DataSet();

            ds = reportBC.GetWorksOrderSummary(AccountID.Value);
            dtWorksOrderSummary = ds.Tables[0];
            gvWorksOrderSummary.DataSource = dtWorksOrderSummary.Select("Site=" + ddlSite.SelectedItem.Text);

On page load the data returned from ReportBC is used as a data source for the grid view. I have been told that to be able to filter the data it would be simpler to use a data table, then bind the data table to the grid view.
When I try to run the code I get this error "Syntax error: Missing operand after 'Oxford' operator."
Not sure if I have explained this very clearly, but can anyone explain this error or point me in the right direction on how I can achieve my goal.

ZurdoDev 19-Jul-13 12:07pm    
So, where is the code that gives that error?
RhysBush 23-Jul-13 4:15am    
Was getting the error on the line
gvWorksOrderSummary.DataSource = dtWorksOrderSummary.Select("Site=" + ddlSite.SelectedItem.Text);
But I've played around with it and its working now.
Thanks guys
ZurdoDev 23-Jul-13 7:37am    
You were missing single quotes around the value. Good to hear it is working now.

try this to filter the data in the datagridview :

protected void ddlSite_SelectedIndexChanged(object sender, EventArgs e)
  (dataGridView1.DataSource as DataTable).DefaultView.RowFilter = string.Format("column name that you need to filter = {0}"+ddlSite.Text);
Share this answer
Just remember to put your data binding code in the page load method in a...

//DataBinding code

To prevent your changes in the selectedindexchanged method from being over written
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