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();
This is an example of sorting in gridview
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