1

我在 .aspx.cs 文件中得到一个字符串值回归,regression = (Session["Regression"]).ToString();然后我想在 SqlDataSource 属性的 SelectCommand 中的 .aspx 文件中使用这个值,如下所示

SelectCommand="SELECT [issue_oid], [issue_num], [regression], 
            [status], [tested_by], [tested_on], [patch_name], [arrived_on], [previous_info], [comment], [is_duplicate] FROM [itt_monthly_patch_issue_list] where status='Not Tested' and `regression='<%#regression%>'"`

.aspx.cs 文件 page_load 方法如下

 protected void Page_Load(object sender, EventArgs e)
    {
            if ((Session["UserName"].ToString()) == string.Empty)
            {
                Server.Transfer("regressionType.aspx");
            }
            regression = (Session["Regression"]).ToString();
            usrname = (Session["UserName"]).ToString();
            DataBind();
     }

请建议我该怎么做?提前致谢...

4

4 回答 4

2

您可以在 SQLDatasource 中设置会话变量的值。像这个例子。

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:testDatabaseConnectionString %>"
    SelectCommand="SELECT * FROM [UserTable] WHERE ([userID] = @UserID)">
    <SelectParameters>
        <asp:SessionParameter Name="UserID" SessionField="UserID" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>

让我们知道对此的任何其他担忧..

于 2012-07-12T05:50:35.693 回答
0

像这样将会话参数添加到您的 sql 数据源

<asp:SqlDataSource SelectCommand="SELECT [issue_oid], [issue_num], [regression], 
        [status], [tested_by], [tested_on], [patch_name], [arrived_on], [previous_info], [comment], [is_duplicate] FROM [itt_monthly_patch_issue_list] where status='Not Tested' and `regression='<%#regression%>'"`>

<SelectParameters>
        <asp:SessionParameter SessionField="Regression" Name="ParameterName" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
于 2012-07-12T05:49:43.197 回答
0

试试这个:

  SelectCommand="SELECT [issue_oid], [issue_num], [regression], 
                [status], [tested_by], [tested_on], [patch_name], [arrived_on], [previous_info], [comment], [is_duplicate] FROM [itt_monthly_patch_issue_list] where status='Not Tested' and `regression='<%=ReturnRegression()%>'"`

在代码隐藏中:

    string regression=null;//Before Page_Load

    protected string ReturnRegression()
    {
    //Write logic here to prevent null being returned
        return regression;
    }
于 2012-07-12T06:18:18.367 回答
0

试试这个:

public StringBuilder regression = new StringBuilder();
regression.Append((Session["Regression"]).ToString());

然后在 .aspx 页面中(在 selct 命令中),您可以使用“回归”作为:

 <% =regression %>
于 2012-07-12T06:55:29.800 回答