1

我正在尝试在源代码的查询中传递 Request.QueryString 整数值。我该怎么做?

http://localhost:3738/WebSite3/UserDetails.aspx?Id=43

我想在查询中传递 id 的值,即 43

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:SLIITComDBConnectionString %>" 

    SelectCommand="SELECT Album.AlbumID, Album.DefaultPhotID, Album.AlbumName, PhotAlbum.Photo FROM Album INNER JOIN PhotAlbum ON Album.DefaultPhotID = PhotAlbum.PhotoID where album.userid= **Request.QueryString[id]** ">
4

2 回答 2

4

使用查询字符串参数

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:SLIITComDBConnectionString %>" 

SelectCommand="SELECT Album.AlbumID, Album.DefaultPhotID, Album.AlbumName, PhotAlbum.Photo FROM Album INNER JOIN PhotAlbum ON Album.DefaultPhotID = PhotAlbum.PhotoID where album.userid= @userid ">
   <SelectParameters>
      <asp:QueryStringParameter Name="userid" Type="String"  QueryStringField="id" />
   </SelectParameters>
</asp:SqlDataSource>
于 2013-02-05T11:53:19.420 回答
0

你可以使用这个:

 <%=this.Request.QueryString["Id"]%>
于 2013-02-05T12:04:57.300 回答