我想从.aspx代码传递会话值,即网络的源代码
<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>
我怀疑这段代码是否有效。
答案 0 :(得分:1)
使用SessionParameter
与SelectParameters
一起传递Session
值
<强> MSDN Doc 强>
<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>