views:

85

answers:

1

I'm attempting to sort a ListView using C#, but whenever I click the sort button it crashes the webpage. Here's my ASP.NET code:

    <asp:ListView ID="list" runat="server" OnSorting="list_Sorting">

        <LayoutTemplate>
            <asp:LinkButton runat="server" ID="Sorter" CommandName="Sort" CommandArgument="DispName" Text="Display Name" />
            <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
        </LayoutTemplate>

        <ItemTemplate>
            <tr>
                <td>
                    <%# Eval("DispName") %>
                </td>
            </tr>
        </ItemTemplate>

    </asp:ListView>

And here's my C# list_Sorting method:

protected void list_Sorting(object sender, ListViewSortEventArgs e)
{
    string sortColumn = e.SortExpression;
    SortDirection sortDirection= (SortDirection) e.SortDirection;
    list.Sort(sortColumn, sortDirection);
    list.DataBind();
} 

Why is it crashing when I try to sort this?

There is no exception, it just says: "WebDev.WebServer.exe has encountered a problem and needs to close."

+7  A: 

The Sorting event is raised when a Sort button is clicked or the Sort method is called

protected void list_Sorting(object sender, ListViewSortEventArgs e)
{
     ...
     list.Sort(sortColumn, sortDirection);
     ...
}

infinite loop

Kikaimaru