Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys

Below I want to filter my gridView and update it acording to the selected option...now the It only pupulates the datagrid but when i try to filter acording to the selected its not doing nothing...Please help

C#
public void populateGridView()
       {

           studentMarksTableAdapter = new OleDbDataAdapter();
           studentsDataSet = new DataSet();
           studentMarksTableAdapter.SelectCommand = dbCmd;
           studentMarksTableAdapter.Fill(studentsDataSet, "StudentMarks");
           gridViewAll.DataSource = studentsDataSet.Tables[0];
       }
       private void Form1_Load(object sender, EventArgs e)
       {

           // Connect to Database:
           string sConnection = "Provider = Microsoft.Ace.OLEDB.12.0;Data Source=Students.accdb";
           dbConn = new OleDbConnection(sConnection);
           dbConn.Open();

           //  Connect the Command to the Connection:
           sql = "SELECT  * FROM StudentMarks ";

           dbCmd = new OleDbCommand();
           dbCmd.CommandText = sql;
           dbCmd.Connection = dbConn;


           populateGridView();



           dbConn.Close();
       }

       private void cboFilter_SelectedIndexChanged(object sender, EventArgs e)
       {
           if (cboFilter.Text == "Student Number")
           {
               sql += "Order By StudentNumber ASC";
               populateGridView();
           }
       }
Posted

1 solution

Did you call something like databind to refresh the gridview?
I am familiar with gridview combining MySQL database to handle the database system, but not familiar with the dataset you use. Typically you need to refresh the datasource first then refresh the gridview, like calling gridview1.DataBind();
 
Share this answer
 
v2
Comments
Dalek Dave 16-Aug-10 19:29pm    
Good call.
Anele Ngqandu 17-Aug-10 5:27am    
It didnt gie me the option for the .DataBing() bt I used .Refresh() but still no changes
Anele Ngqandu 17-Aug-10 5:39am    
hehe...sory for my speling.I mean it did'nt give the option for Databind()

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