2010-10-10 162 views
3

你好,我在我的網站上有這個論壇頁面。我希望用戶發表評論時,舊評論應該位於底部,最新的評論位於頂部。請有人可以幫我嗎?造成這種情況的代碼如下:在網頁上的評論論壇

<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

有什麼問題? – 2010-10-10 22:14:24

+0

由於某種原因,它仍然處於最底層。我希望最近的消息由於某種原因處於頂端,舊的消息處於底部 – onfire4JesusCollins 2010-10-10 22:28:10

回答

2

添加ORDER BY子句您SelectCommand,例如

SELECT * FROM [forum] ORDER BY TheDateTime DESC 

SELECT * FROM [forum] ORDER BY Postingid DESC 
+0

,它仍處於底部。我希望最近的消息在頂部 – onfire4JesusCollins 2010-10-10 22:28:35

+0

'TheDateTime'填寫是否正確?你應該改變它的數據類型爲'datetime'或者一些類似的數據類型;否則,排序是詞法和'2010年10月01日'<'2010年9月14日'... – Heinzi 2010-10-10 22:45:25

+0

非常感謝你的幫助。我確實在數據類型上犯了一個錯誤。而不是我使用的日期時間(nvarchar)。再一次非常感謝你的言語無法表達出來。 – onfire4JesusCollins 2010-10-11 00:27:43