0

我想从 .aspx 代码中传递会话值,即 web 的源代码

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="SELECT Album.AlbumID, Album.DefaultPhotID, Album.AlbumName, PhotAlbum.Photo FROM Album INNER JOIN PhotAlbum ON Album.DefaultPhotID = PhotAlbum.PhotoID where userid=<%  Session["UserId"] %>">
    </asp:SqlDataSource>

我怀疑这段代码是否有效。

4

1 回答 1

1

使用SessionParameterwithSelectParameters传递Session

MSDN 文档

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    SelectCommand="SELECT Album.AlbumID, Album.DefaultPhotID, Album.AlbumName, PhotAlbum.Photo FROM Album INNER JOIN PhotAlbum ON Album.DefaultPhotID = PhotAlbum.PhotoID where userid=@userid">
<SelectParameters>
         <asp:SessionParameter Name="userid" Type="String"  SessionField="UserId" />
</SelectParameters>
   </asp:SqlDataSource>
于 2013-02-04T10:02:35.460 回答