Click here to Skip to main content
15,997,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have a class called ChatMessageBO which has properties such as Id, Msg, Name, and date.

i want to display data datewise.

List<chatmessagebo> SortedList = directChatWindow.messages.OrderBy(o => o.ts).ToList();
MessageList.DataSource = SortedList;
MessageList.DataBind();


here i get all data properly but i want to display date and then name and msg.

example

03-07-2017

jaydeeep hello
rishi hi


04-07-2017

neha god mornin
jaydeep good moring all



view side u can see june 06 2017. where i have to display date.

What I have tried:

<div class="daychat">
                <asp:HiddenField ID="hdnOtherUser" runat="server" />
                <h3><span>June 6, 2017</span></h3>
                <ul class="list-unstyled msglist">
                    <asp:ListView runat="server" ID="MessageList">
                        <ItemTemplate>
                            <li>
                                <div class="media">
                                    <div class="media-left">
                                        <a href="javascript:void(0);">
                                            <img src="../Content/images/1.png" alt="chat-avatar" />
                                        </a>
                                    </div>
                                    <div class="media-body">
                                        <h4 class="media-heading"><a href="javascript:void(0);"><%#Eval("name")%> </a><%# DateTime.Parse(Eval("ts").ToString()).ToString("hh:mm tt")%> </h4>
                                        <p><%#Eval("msg")%></p>  
                                    </div>
                                </div>


                            </li>
                        </ItemTemplate>
                    </asp:ListView>
                </ul>
            </div>
Posted
Updated 4-Jul-17 2:59am

1 solution

Are you saying that you want to group the messages by date?
C#
MessageList.DataSource =  directChatWindow.messages.GroupBy(o => o.ts.Date, (key, items) => new 
{ 
    Date = key, 
    Messages = items.OrderBy(o => o.ts) 
});

MessageList.DataBind(); 

<asp:ListView runat="server" ID="MessageList">
<ItemTemplate>
    <h3><span><%#: Eval("Date", "{0:MMMM d, yyyy}") %></span></h3>
    <ul class="list-unstyled msglist">
        <asp:ListView runat="server" DataSource='<%# Eval("Messages") %>'>
        <ItemTemplate>
            <li>
                <div class="media">
                    <div class="media-left">
                        <a href="javascript:void(0);">
                            <img src="../Content/images/1.png" alt="chat-avatar" />
                        </a>
                    </div>
                    <div class="media-body">
                        <h4 class="media-heading">
                            <a href="javascript:void(0);"><%#: Eval("name") %></a>
                            <%#: Eval("ts", "{0:hh:mm tt}") %> 
                        </h4>
                        <p><%#: Eval("msg") %></p>  
                    </div>
                </div>
            </li>
        </ItemTemplate>
        </asp:ListView>
    </ul>
</ItemTemplate>
</asp:ListView>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900