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 8084341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:45:58+00:00 2026-06-05T17:45:58+00:00

I am having a bit of a strange issue. I have a ListView which

  • 0

I am having a bit of a strange issue.
I have a ListView which I sort in ASC/DESC order by clicking the listview header, using the method below, now the thing is that works perfectly when I have an ObjectDataSource defined and attach that to the ListView.

Now if I just use manual binding using

listview.DataSource = GetListViewContent();
listview.DataBind();

the sorting no longer works. I have tried re-binding in the sort method but still it does not work. Am I missing something?

protected void lvFullReport_Sorting(object sender, ListViewSortEventArgs e)
    {
        Control me = (Control)sender,
           headerRow = me.FindControl("headerRow");

         //Assume that the "header row" control's "control collection" just contains "th"-like control,
         //whose type is exactly "HtmlTableCell" . While we just utilize its properties in the "HtmlControl" level
         //so we cast them as "HtmlControl".
         //What's more , as for these "th" controls , just those who contains an "IButtonControl" ( sorting triggers)
         //are really needed.


        foreach (System.Web.UI.HtmlControls.HtmlControl sortCell in headerRow.Controls.Cast<System.Web.UI.HtmlControls.HtmlControl>()
            .Where(th => th.Controls.OfType<IButtonControl>().Any()))
        {
              //Get out the "only" sorting-Button Control ,
              //for that in a "th" those empty space or literal text area are treated as "Literal Control" ,
              //"literal" fills whole space of "th".

            IButtonControl btnSortField = sortCell.Controls.OfType<IButtonControl>().Single();

            if (btnSortField.CommandArgument == e.SortExpression)
                sortCell.Attributes["class"] = e.SortDirection == SortDirection.Ascending ? "up" : "down";
            else
                if (sortCell.Attributes["class"] != null) sortCell.Attributes.Remove("class");
        }

        DisplayChart();
    }

GetListViewContent() is the source for manual and auto sources and for display purposes both work to show the data; but sorting only works in the auto.

  • 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-06-05T17:45:59+00:00Added an answer on June 5, 2026 at 5:45 pm

    You also need to rebind sorted data. So maybe you should consider implementig your method this way:

    GetListViewContent(SortDirection sortDir);

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

Sidebar

Related Questions

I'm having a strange issue here, i have this bit of code: <?php if
I'm having a strange issue. I have a dynamically created 2D array, Content, which
Having a bit of trouble using the List.Find with a custom predicate i have
I'm having a bit of a strange issue with Nokogiri in Rails. I'm trying
I am having a bit of trouble grabbing some files that have a strange
I'm having a strange error. I have SQL code which looks like: SELECT adverse_reaction_type_id,
I am having some very strange ListView behavior when using a StateListDrawable as the
I'm having a strange issue with a site I'm designing. I'm using the WooCommerce
I'm having a bit of a strange issue that I can't quite figure out.
I'm having a really strange issue, I have a flowplayer video, and next to

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.