在网页上评论论坛

时间:2010-10-10 22:12:29

标签: asp.net

您好我的网站上有这个论坛页面。我希望当用户发表评论时,旧评论应位于底部,新评论应位于顶部。请有人帮帮我吗?代码如下:

<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>

1 个答案:

答案 0 :(得分:2)

SelectCommand添加ORDER BY子句,例如

SELECT * FROM [forum] ORDER BY TheDateTime DESC

SELECT * FROM [forum] ORDER BY Postingid DESC