Skip to Content
0
Former Member
Nov 29, 2007 at 01:35 AM

Change default sort order on search.aspx

86 Views

I want to change the default sort order on SEARCH.ASPX to sort by part number.

WebTools 2007 is currently sorting the results of a parts search by a weighted index. I want it to sort by part number instead.

I tried to solve this by adding code to control the sorting on the gridview. After the gridview is bound to the data source I want to trigger an event to re-sort it. For this to work I need to get access to the datasource. Is there an API that contains the data source?

This is an extract on my current code.

<asp:GridView ID="PartsListGrid" runat="server"

AutoGenerateColumns="False" Width="100%" OnRowDataBound="PartsListGrid_RowDataBound"

PageSize="50" AllowPaging="True"

OnPageIndexChanging="PartsListGrid_PageIndexChanging"

EmptyDataText="No items were found"

AllowSorting="true"

OnDataBound="CustomersGridView_DataBound"

OnSorting ="PartsListGrid_Sorting" >

<scri pt language="C#" runat=server>

void PartsListGrid_Sorting(object sender, GridViewSortEventArgs e)

{

DataTable m_DataTable = PartsListGrid.DataSource as DataTable;

if (m_DataTable != null)

{

DataView m_DataView = new DataView(m_DataTable);

m_DataView.Sort = e.SortExpression + " ASC";

PartsListGrid.DataSource = m_DataView;

PartsListGrid.DataBind();

}

}

void CustomersGridView_DataBound(Object sender, EventArgs e)

{

PartsListGrid.Sort("Product Code", SortDirection.Descending);

}

</script>