Here is the ListView I have for the products page:

<asp:ListView ID="list_view" runat="server" DataSourceID="SqlDataSource1">

    <ItemTemplate>
        <table class="single_product">
            <tr>
                <td>
                    <img src="<%# Eval("image") %>" />
                </td>
                <td>
                    <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />
                </td>
                <td>
                    <asp:Label ID="descriptionLabel" runat="server" Text='<%# Eval("description") %>' />
                </td>
                <td>
                    <form action="comments.aspx" method="post">
                        <input type="hidden" name="prod_id" value="<%# Eval("prod_id") %>">
                        <input type="submit" name="prod_submit" class="button" value="View Comments">
                    </form>
                </td>
            </tr>
        </table>
    </ItemTemplate>

    </asp:ListView>

The user can view the comments for a certain product by clicking the button, taking the prod_id over to the comments page.

Now here is the datasource for the comments page:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:username %>" 
        ProviderName="<%$ ConnectionStrings:username.ProviderName %>"
        InsertCommand="INSERT INTO comment (prod_id, comment_desc, username) VALUES (@prod_id, @comment_desc, @username)"
        SelectCommand="SELECT * FROM comment WHERE prod_id = prod_id ORDER BY comment_date DESC">
    <InsertParameters>
        <asp:Parameter Name="prod_id" Type="Int32" DefaultValue="2" />
        <asp:Parameter Name="comment_desc" Type="String"/>
        <asp:Parameter Name="username" Type="String" />
    </InsertParameters>
    </asp:SqlDataSource>

I want the select to be like this:

SelectCommand="SELECT * FROM comment WHERE prod_id = [value from previous page] ORDER BY comment_date DESC"

I have used Request.Form, etc. but no luck.

I also have other problems but I'll mention them once/if this is solved.

Thank you for any responses.

Try using Session. (C#)

[B]PRODUCTS.aspx[/B]
private void Page_Load(object sender, System.EventArgs e)
    {
         Session["prod_id"] = "value1";
    }

[B]COMMENTS.aspx[/B]
private void Page_Load(object sender, System.EventArgs e)
    {
        string prod_id = (string)(Session["prod_id"]);
    }



<SelectParameters>            
<asp:SessionParameter SessionField="prod_id" DbType="String" Name="Product ID" />   
</SelectParameters>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.