2012-05-15 80 views
1

我有一個論壇的線程表,線程名稱是一個鏈接,一旦點擊它將thread_id傳遞到評論頁面,我需要知道如何顯示所有評論傳遞的thread_id?在網格視圖中通過ID獲取數據

曾嘗試:

<asp:SqlDataSource ID="CommentsDataSource" runat="server" 
SelectCommand="select * from comments where [email protected]_id" > 
<SelectParameters> 
    <asp:QueryStringParameter Name="@thread_id" QueryStringField="thread_id" Runat="Server" /> 
</SelectParameters> 
</asp:SqlDataSource> 

<asp:GridView ID="GridView1" runat="server"> 
    <Columns> 
     <asp:BoundField DataField="comment" HeaderText="Comment" /> 
    </Columns> 
</asp:GridView> 

,但它不工作

感謝

+0

只是什麼下面 – user1389384

回答

0

您可以使用您的數據源的參數從查詢字符串讀取。例如,下面是使用thread_id查詢字符串參數SqlDataSource(假設你的鏈接導航到類似Comments.aspx?thread_id=123

<asp:SqlDataSource ID="CommentsDataSource" runat="server" 
    SelectCommand="select * from comments where [email protected]_id" ...> 
    <SelectParameters> 
     <asp:QueryStringParameter Name="@thread_id" QueryStringField="thread_id" /> 
    </SelectParameters> 
</asp:SqlDataSource> 

<asp:GridView ID="CommentsGrid" runat="server" 
    DataSourceID="CommentsDataSource" ... 
+0

我得到這個錯誤: 無法投類型的對象的System.Web.UI .WebControls.QueryStringParameter'鍵入'System.Web.UIControl' – user1389384

+0

您是否研究過SqlDataSource,SelectParameters和QueryStringParameter是如何工作的?Google將它們作爲粗略的想法。代碼到您的應用程序,並期望它的工作原理,而不理解它背後的目的,以及如何整合到您的特定商業案例。你能否更新你的問題帖子,以顯示你已經嘗試過遠嗎? – mellamokb

+0

更新!我會谷歌他們,看看我能想出什麼。 – user1389384