Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

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>

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...