Sorting With Summarys

Nate Bross

Well-known member
Joined
Apr 6, 2005
Messages
601
Location
Chicago, IL
Im trying to get functionallity similar to the way Outlook sorts messages.

Today
Item1
Item2
Item3
Yesterday
Item1
Item2
Item3
Last Week
Item1
Item2
Item3

Is this doable with a GridView or should I use a Repeater?

Just looking for some ideas to get me going in the right direction.
 
So I ended up using a nested list, and nested GridViews.

Code Behind
C#:
  
            List<obj> FoundObjects;

            DataAccess da = new DataAccess(currentSession);
            FoundObjects = da.GetObjects();

            List<List<obj>> OrderedObjects = new List<List<obj>>(50);

            var x = from ojb o in FoundObjects
                    select o.GetType().InvokeMember("sortColumn", System.Reflection.BindingFlags.GetProperty, null, o, null);
            
            var distinct = Enumerable.Distinct(x);

            foreach (object sortObject in distinct)
            {
                OrderedObjects.Add((from obj o in FoundObjects
                                   where t.GetType().InvokeMember("sortColumn", System.Reflection.BindingFlags.GetProperty, null, o, null).ToString().Contains(sortObject.ToString())
                                   select o).ToList());
            }

            dgvObjects.DataSource = OrderedObjects;
            dgvObjects.DataBind();
        }

        // important piece
        protected void dgvObjects_RowDataBound(Object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                List<Task> tasks = (List<Task>)e.Row.DataItem;
                GridView gvSub = (GridView)e.Row.FindControl("dgvObjectsSub");
                gvSub.DataSource = tasks;
                gvSub.DataBind();
            }
        }

Markup
Code:
<asp:GridView AutoGenerateColumns="false"
                runat="server"
                Width="100%"
                ID="dgvObjects" 
                AllowSorting="true"
                OnRowDataBound="dgvObjects_RowDataBound">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                               <asp:GridView runat="server"
                                ID="dgvObjectsSub" 
                                AutoGenerateColumns="False" 
                                CellPadding="4" 
                                AllowPaging="True"
                                AllowSorting="true"
                                BorderStyle="None"
                                BorderWidth="0px" 
                                GridLines="None"
                                Width="100%"
                                Height="100%"
                                PageSize="4"
                                EmptyDataRowStyle-CssClass="listbold"
                                EmptyDataText="No Records Found.">
                            </asp:GridView> 
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
 
Back
Top