Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 414237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:15:47+00:00 2026-05-12T18:15:47+00:00

I am using C# and .NET 3.5 and have a GridView that I am

  • 0

I am using C# and .NET 3.5 and have a GridView that I am setting the dataSource programatically in the code-behind page. I have data in a DataTable and then depending on a column value (isValid boolean) of each Row, I create a new row using DataRowView.AddNew() method into 1 of 2 DataViews – dvValid or dvInvalid. I am NOT creating a new DataTable.NewRow to add to the DataView Table. Then I bind the GridView to the appropriate dataView.

There is a problem when I am sorting the GridView. I am having a problem with 1 row not being sorted correctly, all other rows are sorted fine. I debugged my code and found that the DataView.Count is 1 more than the DataView.Table.Rows.Count even though I am calling DataView.Table.AcceptChanges() method. This is strange since the dataTable should have all committed rows and therefore the counts should be the same.

So why are the 2 counts different? A DataView is a subset of the DataTable so should it not have equal or less rows than the DataTable.
When I populate the DataView, should I first create the DataTables rather than creating the DataView directly? Right now, I am directly creating a DataRowView without a dDataTableRow, is this the correct approach?

Thanks for your help.

Code snippet : C#

…

//get the data as DataTable
members = GetMemberDataTable ();

//create views from a new DataTable with no rows
dvValidMembers = new DataView (CreateMembersDT("ValidMembers"));
dvInValidMembers = new DataView (CreateMembersDT("InvalidMembers"));

//iterate thru each row and put into appropriate DataView
foreach (DataRow memberRow in members.Rows)
            {
                if ((bool)memberRow["isValid"])
                    //Add to valid members Dview
                    member = dvValidMembers.AddNew();
                else
                    //add to InValid members Dview
                    member = dvInvalidMembers.AddNew();

                member["memberID"] = memberRow["memID"];

            } //foreach

    dvInvalidMembers.Table.AcceptChanges();
    dvValidMembers.Table.AcceptChanges();

 }

 private System.Data.DataTable CreateMembersDT ( string tableName)
    {
        System.Data.DataTable dtMembers = new System.Data.DataTable(tableName);

        dtMembers.Columns.Add(new DataColumn("memID", typeof(int)));

        return dtMembers;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:15:47+00:00Added an answer on May 12, 2026 at 6:15 pm

    That 1 row that isn’t sorting right, could that be the last row?

    I think you are missing a DataView.EndEdit():

    foreach (DataRow memberRow in members.Rows)
    {
        DataView dv;
        if (...) 
            //Add to valid members Dview
            dv = dvValidMembers;
        else
            dv = dvInvalidMembers;
    
        member = dv.Addnew();
        member["memberID"] = memberRow["memID"];
        dv.EndEdit();
    }
    

    But I would also like to note that you could probably use 2 Views with a Filter on isValid and then you would only need to point them to the original members table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 240k
  • Answers 240k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Each pane is not a separate view. By doing that… May 13, 2026 at 7:13 am
  • Editorial Team
    Editorial Team added an answer I just tested this by writing a subclass of UITextField… May 13, 2026 at 7:13 am
  • Editorial Team
    Editorial Team added an answer Try this app: http://knomedia.com/air/badgeBuilder/ - Badge Builder May 13, 2026 at 7:13 am

Related Questions

Background I am using interface-based programming on a current project and have run into
I have the following List<int> collection and I need to find the highest integer
I am unable to figure out how to make my user control react to
I am using the URL for an HTTP resource as unique identifiers for the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.