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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:14:14+00:00 2026-06-08T15:14:14+00:00

I need the gridview to be displayed based on the dropdownlist : LastestTransactionFirst, EarlierTransactionFirst.

  • 0

I need the gridview to be displayed based on the dropdownlist : LastestTransactionFirst, EarlierTransactionFirst. So basically it’s desc or asc based on the date in gridview. May i know how should i go about it ?

This is my code for gridview selection. But I had a dropdownlist and need the gridview to appear based on the dropdownlist selection.

    myConnection.ConnectionString = strConnectionString;
    SqlCommand cmd = new SqlCommand("SELECT thDate, thType, thAmountIn, thAmountOut from [Transaction] ORDER BY thDate, thType, thAmountIn, thAmountOut DESC", myConnection);
    myConnection.Open();
    SqlDataReader reader1 = cmd.ExecuteReader();
    GridView1.DataSource = reader1;
    GridView1.DataBind();
  • 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-08T15:14:17+00:00Added an answer on June 8, 2026 at 3:14 pm

    This is an example of sorting in gridview

    DataView dvItems = new DataView((DataTable)ds.Tables["datatable1"]);
    
     if (ddl_itemsorderby.SelectedValue == "MenuGroup")
         dvItems.Sort = "Menu_Group, Item_Name ASC";
     else if (ddl_itemsorderby.SelectedValue == "Item")
         dvItems.Sort = "Item_Name, Menu_Group ASC";
     else if (ddl_itemsorderby.SelectedValue == "Rate")
         dvItems.Sort = "Item_rate, Item_Name ASC";
     else if (ddl_itemsorderby.SelectedValue == "Quantity")
         dvItems.Sort = "Item_Quantity, Item_Name ASC";
    
     gridview1.DataSource = dvItems;
     gridview1.DataBind();
    

    Here Menu_Group,Item_name … are the column names in the datatable which you bind to the gridview.

    “Menu_Group, Item_Name ASC” This means that The forse order prority will be given to the Menu_Group first and second order priority will be given to Item_Name.
    ASC is the Order type will be ascending

    ddl_itemsorderby is the dropdownlist from which the column order will be selected.
    dvitems is the dataview.

    ASC is the ascending order.

    You have to create a dataview containing the data in the datatable and then sort the values in the dataview and then bind the dataview to the gridview

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

Sidebar

Related Questions

I need to manually page a GridView based report, i.e. add a second page
I'm getting data from DB and displayed in a GridView fine. But I need
I need to display all the employees in one webpart. I created the gridview
I need a GridView, but in each grid, there will be an ImageView and
I need a GridView with rows with different height. Only for rows, not for
I need to export a gridview to excel, I put the return html code
Need some help with DataFormatString in GridView. I have a Double value that needs
I need to bind width property of the GridView column that is created dynamically
i need to set image as background in android gridview. I have code which
I have a GridView that I need to dynamically add TemplateField elements to. My

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.