Click here to Skip to main content
14,735,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually I wanted to know about sorting of listview on dropdownlist index chaged event.
like when user select asc or desc in dropdownlist sorting should be applied on listview.


1 solution

Refer this LINK
Listview sorting based on dropdownlist in asc or desc [^]

<asp:dropdownlist id="ddlDirection" runat="server" xmlns:asp="#unknown">
AutoPostBack="true" onselectedindexchanged="ddlDirection_SelectedIndexChanged1">
<asp:listitem selected="True" text="Ascending">ASC</asp:listitem>
<asp:listitem text="Descending">DESC</asp:listitem>

the codebehind will be something on the following lines

 protected void ddlDirection_SelectedIndexChanged1(object sender, EventArgs e)
        string sortBy = ddlSortBy.SelectedValue; //any string u want to sort (name etc)
        string direction = ddlDirection.SelectedValue;
        SortProducts(sortBy, direction);

 protected void SortProducts(string sortBy, string direction)
        string filter = sortBy + " " + direction;
        DataTable newDt = new DataTable();
        newDt = (DataTable)Session["ProductsDt"];

        dt = newDt.Clone();

        DataRow[] drArray = null;

        drArray = newDt.Select("", filter);

        foreach (DataRow dr in drArray)

        MyListView.DataSource = dt;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900