Problem with Sorted Data in GridView RRS feed

  • Question

  • I am having an issue where the data that is in my gridview is not in the order it is coming from the query that populates the gridview.

    The GridView is populated by a dataset that is filled via a SQLDataAdapter. The query that is run in sql returns the results in a specific order, but that is not being reflected in the gridview. Here is the code:

     DataSet scDS = new DataSet();
     dbConnection = new SqlConnection(ConnectionString);
    SqlCommand GetScoreCardCmd = new SqlCommand(theSQL, dbConnection);
    SqlDataAdapter scDA = new SqlDataAdapter();
    scDA.SelectCommand = GetScoreCardCmd;
    scDA.Fill(scDS, "Thedata");
    theGridView.DataSource = scDS.Tables["Thedata"];

    How come the gridview is not displaying the same result order as the sql query? What can I do to fix it?


    Wednesday, March 13, 2013 6:02 PM


  • Check your GridView properties and make sure columns in GridView doesn't have sorting applied.

    Gaurav Khanna | Microsoft VB.NET MVP | Microsoft Community Contributor

    • Marked as answer by Bob Shen Friday, March 22, 2013 9:11 AM
    Wednesday, March 13, 2013 6:55 PM