Sorting DataGrid using Table.Select() DataRow Array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joelzn
    New Member
    • Oct 2008
    • 2

    Sorting DataGrid using Table.Select() DataRow Array

    I have a hand built dataset where some columns come from a sql database and others are calculated and eventually I will have two different query results going into one table because its impossible for me to get all the data w/one query.

    The problem I need help with is getting the DataGrid to reflect changes from a sort.

    The foundRows DataRow array contains correctly sorted rows (verified), but I can't get the table updated in the DataGrid. I think my problem has to do with ViewState but I'm not sure. How would I update DataGrid from the sort results?

    Code:
        void dgridResults_SortCommand(object source, DataGridSortCommandEventArgs e)
        {
            collectionId = int.Parse(HttpUtility.UrlDecode(Request.QueryString["collectionId"]));
            dsBuilder.GetResultsDataSet(dsResults, collectionId);
            DataRow[] foundRows = dsResults.Tables["ResultTable"].Select("JobId > 0", "JobId ASC");
    
            for (int index = 0; index < foundRows.Length; index++)
            {
                dsResults.Tables[RESULT_TABLE].Rows[index].BeginEdit();
                dsResults.Tables[RESULT_TABLE].Rows[index].ItemArray = foundRows[index].ItemArray;
                dsResults.Tables[RESULT_TABLE].Rows[index].EndEdit();
                dsResults.Tables[RESULT_TABLE].Rows[index].AcceptChanges();
            }
    
            dgridResults.DataSource = dsResults;
            dgridResults.DataBind();
    
        }
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi joelzn,

    Welcome to Bytes.com! I hope you find the site useful.

    You've posted your question in the ASP Forum which is for Classic ASP only - I've moved it for you but in future please post all ASP.NET questions in the .NET Forum.

    Thanks,

    Dr B

    Comment

    • joelzn
      New Member
      • Oct 2008
      • 2

      #3
      I was going about it the wrong way, here is the solution:

      I removed the for loop and did this:

      Code:
              DataView dv = dsResults.Tables[RESULT_TABLE].DefaultView;
              dv.Sort = "JobId ASC";
              dgridResults.DataSource = dv;
              dgridResults.DataBind();

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        Glad you got it sorted, thanks for posting the solution.

        Dr B

        Comment

        Working...