1

我有一个包含论坛线程的表,线程名称是一个链接,一旦单击它将 thread_id 传递到评论页面,我需要知道如何显示所有带有传递的 thread_id 的评论?

试过:

<asp:SqlDataSource ID="CommentsDataSource" runat="server"
SelectCommand="select * from comments where thread_id=@thread_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>

但它不起作用

谢谢

4

1 回答 1

0

您可以在数据源中使用从 QueryString 读取的参数。例如,这里是一个SqlDataSource使用thread_id查询字符串参数(假设您的链接导航到类似Comments.aspx?thread_id=123

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

<asp:GridView ID="CommentsGrid" runat="server"
    DataSourceID="CommentsDataSource" ...
于 2012-05-15T14:34:11.433 回答