将 NavigateUrl Id 传递给下一页 Sql 语句
我正在 asp.net 中编码“列出所有产品”页面。我做了从数据库到 ViewList 的连接。现在我必须使产品可点击。到目前为止,我在 asp 部分中编码的内容如下:
<div class="image">
<asp:HyperLink ID="HyperLinkSaleDesign" runat="server" NavigateUrl='<%# Eval("ID" , "~/EN/ViewTemplate.aspx?id={0}") %>'>
<asp:Image ID="ImageSaleDesign" runat="server" Width="247" Height="150" ImageUrl='<%# Eval("thumb") %>' />
</asp:HyperLink>
</div>
导航 URL 有效,我可以看到所选的“?id={0}”。 但是我无法正确传递数据,因此下一页的 SQL 查询不起作用。
我不确定如何将此值传递给 Select 语句。这是我到目前为止所做的:
String IDquery = ("QueryStringParameter[ID]"); // doesn't work
try
{
string ConnectionString = WebConfigurationManager.ConnectionStrings["Twebconfig"].ConnectionString;
SqlConnection viewTemplate = new SqlConnection(ConnectionString);
SqlDataAdapter viewTemplateSet = new SqlDataAdapter("SELECT " +
" * FROM saleDesigns WHERE ID = @IDquery", viewTemplate); // doesn't seem to see the variable
Data Binding - etc. etc. etc
}
catch (Exception err)
{
mylabel.Text = "Invalid " + err.Message;
}
我愿意接受任何建议。 谢谢。
I am coding "List all Product" page in asp.net. I did the connection from the DB to ViewList. Now I have to make the products clickable. What I have coded so far in the asp part is , as it follows:
<div class="image">
<asp:HyperLink ID="HyperLinkSaleDesign" runat="server" NavigateUrl='<%# Eval("ID" , "~/EN/ViewTemplate.aspx?id={0}") %>'>
<asp:Image ID="ImageSaleDesign" runat="server" Width="247" Height="150" ImageUrl='<%# Eval("thumb") %>' />
</asp:HyperLink>
</div>
The navigation URL works and I can see the selected "?id={0}".
However I cannot pass the data correctly , so the SQL query on the next page does not work.
I am not sure how to pass this value to the Select statement. Here is what I have done so far:
String IDquery = ("QueryStringParameter[ID]"); // doesn't work
try
{
string ConnectionString = WebConfigurationManager.ConnectionStrings["Twebconfig"].ConnectionString;
SqlConnection viewTemplate = new SqlConnection(ConnectionString);
SqlDataAdapter viewTemplateSet = new SqlDataAdapter("SELECT " +
" * FROM saleDesigns WHERE ID = @IDquery", viewTemplate); // doesn't seem to see the variable
Data Binding - etc. etc. etc
}
catch (Exception err)
{
mylabel.Text = "Invalid " + err.Message;
}
I am open to any suggestions.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对你的代码有点困惑,但看起来你只需要从 QueryString 检索 id 并用它构建 SQL 查询,对吧?
这是您想要做的吗?:
您可以使用 QueryString 中的 ID 将查询放在一起,您可以执行如下操作:
I'm a bit confused by your code, but it looks like you just need to retrieve the
id
from QueryString and build a SQL query with it, right?Is this what you're trying to do?:
You can put the query together using the ID from QueryString, you can do something like this:
这就是它对我有用的方式:
This is the way it works for me: