繁体   English   中英

如何在ASP.Net中使用SqlDataSource将Session值添加到DropDownList?

[英]How to add Session value to DropDownList using SqlDataSource in ASP.Net?

我有一个DropDownList,它与SqlDataSource连接,我在那个DropDownList中传递了两个值

TotalSales =它是默认值TotalSales

2.UserID =它是会话值Session [“ UserID”]

这是我的代码

Aspx.code

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HQWebMatajer13 %>" SelectCommand="SELECT [UserFileName] FROM [ReportSave] WHERE (([ReportName] = @ReportName) AND ([UserID] = @UserID))">
    <SelectParameters>
        <asp:Parameter DefaultValue="TotalSales" Name="ReportName" Type="String" />
        <asp:SessionParameter Name="UserID" SessionField="UserID" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

这里是 图片

我已经在上一页的UserReports.aspx中的会话中传递了值

该页面代码:

protected void linkTotalSales_Click(object sender, EventArgs e)
{
    Session["UserID"] = Session["UserID"].ToString();
    Response.Redirect("ReportTotalSalesPivot.aspx");
}

当我从UserReports.aspx页单击TotalSales的链接时。 它显示以下错误

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'UserID'.

显示错误是因为在数据源中您没有选择UserId和ReportName。 您只是在WHERE子句中将它们用作条件。

我不明白你为什么这样

 Session["UserId"] = Session["UserId"].ToString();

因为您的会话中已经有一个字符串变量。 另外要注意的是,会话将在整个Web应用程序中都是动态的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM