Sort a Datagrid in Dreamweaver MX
I have got a demo on how to sort a table by clicking on a column heading in Classic ASP. It's just as easy to do something similar in ASP using a Datagrid in Dreamweaver MX. First, you'd create a Dataset and bind it to a Datagrid as you'd do normally. Then, you'd allow sorting on the datagrid (AllowSorting="true") and declare a command for the onsort event (OnSortCommand="chSortGrid"). Your datagrid will now look like:
<asp:DataGrid id="DataGrid1" runat="server" AllowSorting="true" AutoGenerateColumns="false" CellPadding="3" CellSpacing="0" ShowFooter="false" ShowHeader="true" DataSource="<%# DataSet1.DefaultView %>" PagerStyle-Mode="NextPrev" OnSortCommand="chSortGrid" >
If AutoGenerateColumns has been set to false, then we must assign a sort expression to each column in the datagrid. eg.
<asp:BoundColumn DataField="ProductID"
HeaderText="ProductID"
ReadOnly="true"
SortExpression="ProductID"
Visible="true" runat="server"/>
The sort expression will be equal to the corresponding column name in the Dataset. Next, we can add the function that will sort the grid:
<script runat="server">
protected void chSortGrid(Object sender, DataGridSortCommandEventArgs e)
{
System.Data.DataView dv=DataSet1.DefaultView;
dv.Sort=e.SortExpression.ToString();
DataGrid1.DataSource=dv;
DataGrid1.DataBind();
}
</script>
Lastly, we can alter the default values of the MM:PageBind tag. We don't want databinding to occur after the form has been submitted, so we'll use:
<MM:PageBind runat="server" PostBackBind="false" />
Click on the link below to download the support files that come with this article.

