【问题标题】:how to set passing variable in SelectCommand Asp.net如何在 SelectCommand Asp.net 中设置传递变量
【发布时间】:2015-01-19 13:59:06
【问题描述】:

我尝试了这个例子,但没有用。

<%string id = Request.QueryString["id"]; %>// get value and set in one variable
<%=id%>// display successfully variable's value
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
SelectCommand="SELECT [id], [name], [image], [old_price], [new_price] FROM [product] where [id]= "'<%=id%>'"" ></asp:SqlDataSource>

SelectCommand 中的问题如何在查询中设置变量我尝试像

【问题讨论】:

  • SelectCommand 中的问题如何在查询中设置变量我尝试像 。
  • 我强烈建议您不要将应用的表示层与数据层混为一谈。有很多原因。其中,安全、逻辑解耦、维护。请不要那样做。有关 SelectCommand 的更多详细信息,请查看here
  • 此链接可能对您有所帮助..stackoverflow.com/questions/3319358/…
  • 我没有在 gridview 中显示数据库。在普通的 html 表中。

标签: c# asp.net


【解决方案1】:

使用代码隐藏,例如Selecting event:

<asp:SqlDataSource ID="SqlDataSource1" ... OnSelecting="Product_Selecting">

代码隐藏:

protected void Product_Selecting(object sender, SqlDataSourceCommandEventArgs e)
{
    e.Command.Parameters[0].Value = Request.QueryString["id"];
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-03
    • 2018-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 2017-03-10
    • 1970-01-01
    相关资源
    最近更新 更多