M
Martin Gregersen
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_PageIndexChanging" 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="<%$ Resources
bjCustomer, Number %>">
<ItemTemplate>
<%# link("ElementID",Eval("ElementId"),Eval("ElementNumber"))%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources
bjCustomer, Phone %>" SortExpression="Phone">
<ItemTemplate>
<%# (Eval("Address.Phone")) %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Title" HeaderText="<%$ Resources
bjCustomer, Title %>" SortExpression="Title" />
<asp:TemplateField HeaderText="<%$ Resources
bjCustomer, Attention %>">
<ItemTemplate>
<%# (Eval("Address.Contact")) %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources
bjCustomer, 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>
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_PageIndexChanging" 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="<%$ Resources
<ItemTemplate>
<%# link("ElementID",Eval("ElementId"),Eval("ElementNumber"))%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources
<ItemTemplate>
<%# (Eval("Address.Phone")) %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Title" HeaderText="<%$ Resources
<asp:TemplateField HeaderText="<%$ Resources
<ItemTemplate>
<%# (Eval("Address.Contact")) %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources
<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>