我有这个代码示例。该网页将由另一个通过URL传递ID的网页调用,例如http://localhost:49780/bookingform.aspx?passedid=8
如何将该ID输入我的selectcommand以过滤掉我的记录?例如ProductID< = passid
代码:
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Repeater.DataSourceID Property Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>Repeater.DataSourceID Property Example</h3>
<asp:repeater id="Repeater1"
datasourceid="SqlDataSource1"
runat="server">
<headertemplate>
<table border="1">
<tr>
<td><b>Product ID</b></td>
<td><b>Product Name</b></td>
</tr>
</headertemplate>
<itemtemplate>
<tr>
<td> <%# Eval("ProductID") %> </td>
<td> <%# Eval("ProductName") %> </td>
</tr>
</itemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:repeater>
<asp:sqldatasource id="SqlDataSource1"
connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"
selectcommand="SELECT ProductID, ProductName FROM [Products] Where ProductID <= 10"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
此致
茶
答案 0 :(得分:0)
您好,您可以将查询字符串作为参数
传递给sqlconnection <asp:sqldatasource id="SqlDataSource1"
connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"
selectcommand="Procedure Name" CommandType="Procedure"
runat="server">
<SelectParameters>
<asp:QueryStringParameter Name="ProductID " QueryStringField="passedidc" Type="Int32" />
<SelectParameter>
</asp:sqldatasource>
唯一的问题是,而不是在页面上使用查询,您需要使用过程并传递过程名称来选择命令。
答案 1 :(得分:0)
private int _querystring=string.empty;
public int QueryString
{
get
{
return _querystring;
}
set
{
_querystring=value;
}
QueryString=Convert.ToInt32(Request.QueryString["passedid"].ToString());
在代码中传递此值
selectcommand='SELECT ProductID, ProductName FROM [Products] Where ProductID="<%=QueryString>"'