Nate Bross Posted June 9, 2008 Posted June 9, 2008 I'm 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. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted June 12, 2008 Author Posted June 12, 2008 So I ended up using a nested list, and nested GridViews. Code Behind 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 <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> Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.