Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Sorting with datasource ArrayList

Reply
Thread Tools

Sorting with datasource ArrayList

 
 
Martin Gregersen
Guest
Posts: n/a
 
      11-10-2006
Hi everybody

I have a GridView control where my datasource is an ArrayList, I would like to be able to sort the grid, therefore I set the AllowSorting to true, so far so good. The ArrayList consist of a collection of Customer-objects, where the "Title" (a string) is the name of the Customer.

Below is my sourcecode for the Sorting event and the control itself, I don't know what is wrong, but when I click a column to sort I get an: System.StackOverflowException was unhandled

Can anyone please show an example of a sorting that works with an ArrayList as datasource in a grid.

If you need any addiotnal details let me know. )

Thanks in advance

Martin Gregersen
WebShine A/S
gregersen(add)webshine(dot)dk

--- gwCustomerList_Sorting Source ----

protected void gwCustomerList_Sorting(object sender, GridViewSortEventArgs e)

{

Trace.Write("Customers.aspx.cs", "gwCustomerList_Sorting(object sender, GridViewSortEventArgs e)");



try

{

Trace.Write("SortExpression: " + e.SortExpression.ToString());

Trace.Write("SortDirection: " + e.SortDirection.ToString());

gwCustomerList.DataSource = _alCustomerList;

gwCustomerList.Sort(e.SortExpression, e.SortDirection);

gwCustomerList.DataBind();

}

catch (Exception ex)

{

Trace.Write("Exception: " + ex.Message);

}

}


---- Grid Source ----
<asp:GridView ID="gwCustomerList" runat="server" AutoGenerateColumns="False"

CellPadding="4" ForeColor="#333333" GridLines="None" OnPageIndexChanging="gwCustomerList_PageIndexChang ing" PageSize="15" AllowPaging="True" meta:resourcekey="gwCustomerListResource1" AllowSorting="True" OnSorting="gwCustomerList_Sorting">

<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

<Columns>

<asp:TemplateField SortExpression="ElementNumber" HeaderText="<%$ ResourcesbjCustomer, Number %>">

<ItemTemplate>

<%# link("ElementID",Eval("ElementId"),Eval("ElementNu mber"))%>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="<%$ ResourcesbjCustomer, Phone %>" SortExpression="Phone">

<ItemTemplate>

<%# (Eval("Address.Phone")) %>

</ItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField="Title" HeaderText="<%$ ResourcesbjCustomer, Title %>" SortExpression="Title" />

<asp:TemplateField HeaderText="<%$ ResourcesbjCustomer, Attention %>">

<ItemTemplate>

<%# (Eval("Address.Contact")) %>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="<%$ ResourcesbjCustomer, Address %>">

<ItemTemplate>

<%# (Eval("Address.Address1")) %>

</ItemTemplate>

</asp:TemplateField>

</Columns>

<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

<EditRowStyle BackColor="#999999" />

<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />

<AlternatingRowStyle BackColor="Beige" ForeColor="#333333" />

</asp:GridView>



 
Reply With Quote
 
 
 
 
mtadd
Guest
Posts: n/a
 
      11-10-2006
The Sort method of the Gridview control raises the Sorting and Sorted
Events...that's why you're getting a stack overflow. Instead, you
should sort your data source (_alCustomerList) according to the
SortDirection and SortExpression provided by the EventArgs prior to
Databinding it to the Gridview in the Sorting Event.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clear Arraylist vs new ArrayList Philipp Java 6 05-28-2008 09:07 PM
Does the clone() method of ArrayList<> make a copy of the objects in the ArrayList? xz Java 16 08-04-2007 10:33 PM
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList leal ting ASP .Net 1 02-10-2004 07:45 PM
writeObject with ArrayList of ArrayList? Kaidi Java 4 01-03-2004 08:16 PM
Iterate through ArrayList using an another ArrayList Saravanan Rathinavelu ASP .Net 3 08-19-2003 07:03 AM



Advertisments