<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AppConnectionString %>" SelectCommand="SELECT ProductInfo.ProductName, ProductInfo.ProductPrice, ProductInfo.ClickCount, ProductInfo.new, ProductInfo.AddTime, ProductInfo.Oriprice, ProductInfo.SavePrice, ProductInfo.discount, ProductInfo.ImagesUrl, ProductInfo.UserID, ProductInfo.schoolID, school.schoolName, school.schoolID AS Expr1 FROM ProductInfo INNER JOIN school ON ProductInfo.schoolID = school.schoolID WHERE (ProductInfo.ProductName LIKE '%' + @ProductName + '%')" >
<SelectParameters>
<asp:QueryStringParameter Name="ProductName" QueryStringField="com" />
</SelectParameters>
</asp:SqlDataSource>
红色部分的我在前台的html代码中不能用变量,我想用变量代替红色的内容。
就像下面的代码可以在后台CS文件中执行。但放在前台就用不了了。
因为使用了分页。所以必须在前台直接赋值。否则像下面的在后台绑定。分页效果就不能用了 this.SqlDataSource1.SelectCommand = "SELECT ProductInfo.ProductName, ProductInfo.ProductPrice, ProductInfo.ClickCount, ProductInfo.new, ProductInfo.AddTime, ProductInfo.Oriprice, ProductInfo.SavePrice, ProductInfo.discount, ProductInfo.ImagesUrl, ProductInfo.UserID, ProductInfo.schoolID, school.schoolName, school.schoolID AS Expr1 FROM ProductInfo INNER JOIN school ON ProductInfo.schoolID = school.schoolID WHERE (" + Request.QueryString["sql"] + " LIKE '%" + Request.QueryString["com"] + "%')";
在.CS文件的 page_load 事件函数之前声明一个变量:
public string SQL = "";
// protected void Page_Load(object sender, EventArgs e)
然后再到Page_Load(object sender, EventArgs e)事件中为它赋值:
if (Request.QueryString["sql"] != null)
{
SQL = Request.QueryString["sql"];
}在前台aspx文件中就可以在相应的地方用<%=SQL%>来引用值了
使用VS2005自动生成的代码的话。前台代码怎么写
<SelectParameters >
<asp:ControlParameter Name= "ProductName " ControlId="DropDwonList1" PropertyName="selectValue" / >
</SelectParameters >
</asp:SqlDataSource >
你试试这个..前台加个DROPDOWNLIST 列出所有产品的名称
ProductInfo.ProductName 用的是DropDwonList的值
@Productname 用的是textbox值。
有两个变量啊。
如果只有一个变量的话,像szjstar当然可以实现。但问题是 ProductInfo.ProductName也是个变量。该如何表示呢?