tags:

views:

36

answers:

1

Hello i have this forum page on my website. I want when users leave comment, the old comments should be at the bottom and new comments at the top. Please can someone help me with that please? The code for that is below:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" 
        DeleteCommand="DELETE FROM [forum] WHERE [Postingid] = @Postingid" 
        InsertCommand="INSERT INTO [forum] ([UserName], [TheDateTime], [Subject], [Message]) VALUES (@UserName, @TheDateTime, @Subject, @Message)" 
        SelectCommand="SELECT * FROM [forum] " 
        UpdateCommand="UPDATE [forum] SET [UserName] = @UserName, [TheDateTime] = @TheDateTime, [Subject] = @Subject, [Message] = @Message WHERE [Postingid] = @Postingid">
        <DeleteParameters>
            <asp:Parameter Name="Postingid" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="UserName" Type="String" />
            <asp:Parameter Name="TheDateTime" Type="String" />
            <asp:Parameter Name="Subject" Type="String" />
            <asp:Parameter Name="Message" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="UserName" Type="String" />
            <asp:Parameter Name="TheDateTime" Type="String" />
            <asp:Parameter Name="Subject" Type="String" />
            <asp:Parameter Name="Message" Type="String" />
            <asp:Parameter Name="Postingid" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>

</div>
<center>
<font color="gray" size="+2">Daily Christian News and Discussion Area</font><br />

<hr style=" border-bottom:1px dotted silver;" />

<font color="brown" size="+1">Old Posting(Messages)</font><br />

<asp:ListView ID="ListView1" runat="server"  
    DataSourceID="SqlDataSource1">
    <LayoutTemplate>
    <div id="ItemPlaceHolderContainer" runat="server">
    <span id="ItemPlaceHolder" runat="server"></span>
    </div>
    </LayoutTemplate>


    <ItemTemplate>
    <div class="news">
    <span style="font-style:italic; color:#008000">Posted By <%# Eval("UserName")%> On <%# Eval("TheDateTime")%></span><br />
    <strong><font color="orange" size="+1">Subject: </font><%# Eval("Subject")%></strong><br />
   <p> <%# Eval("Message")%></p>
    </div>
    </ItemTemplate>
    <AlternatingItemTemplate>
     <div class="newsAlternate">
    <span style="font-style:italic; color:#008000">Posted By <%# Eval("UserName")%> On <%# Eval("TheDateTime")%></span><br />
    <strong><font color="orange" size="+1">Subject:</font> <%# Eval("Subject")%></strong><br />
   <p> <%# Eval("Message")%></p>
    </div>
    </AlternatingItemTemplate>
</asp:ListView>
<br />
<table>

<tr>
<td><font color="brown" size="+1">New Posting(Messages)</font><br /><hr style=" border-bottom:1px dotted silver;" /></td>
</tr>

<tr>
<td> Subject:</td>
<td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Message:</td>
<td><asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="Button1" runat="server" Text="Post" /></td>
</tr>
</table>
</center>
+2  A: 

Add an ORDER BY clause to your SelectCommand, e.g.

SELECT * FROM [forum] ORDER BY TheDateTime DESC

or

SELECT * FROM [forum] ORDER BY Postingid DESC
Heinzi
for some reason, it's still at the bottom. I want the recent messages to be at the top
onfire4JesusCollins
Is `TheDateTime` filled correctly? And you should change its data type to `datetime` or some similar data type; otherwise, sorting is lexical and `01 Oct 2010` < `14 Sept 2010`...
Heinzi
Thank you very much for the help. I did made a mistake with the data type. instead of datetime i used (nvarchar). Once again thank you very much word cannot express it.
onfire4JesusCollins