【问题标题】:passing querystring传递查询字符串
【发布时间】:2010-10-16 16:45:56
【问题描述】:

考虑一个页面,当页面加载时,什么都没有显示。

当我在浏览器上传递查询字符串时它可以工作:

http://localhost:51765/foo/foo.aspx?ID=c516f4f4-36a9-40a7-baad-d2419ea631b9

我希望它在页面加载时而不是在我在浏览器上传递查询字符串时工作。

有人可以帮我解决这个问题吗?

<asp:SqlDataSource ID="categoriesDataSource" runat="server" 
     connectionString="<%$ ConnectionStrings:ConnectionString %>"
     SelectCommand="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]">
     <SelectParameters>
          <asp:QueryStringParameter Name="UserId" QueryStringField="ID" />
     </SelectParameters>
</asp:SqlDataSource>

<asp:DropDownList ID="categories" runat="server" AutoPostBack="True"
       DataSourceID="categoriesDataSource" DataTextField="Name" 
         AppendDataBoundItems="True" DataValueField="CategoryID">
        <asp:ListItem  Value="">-- All Albums --</asp:ListItem>
</asp:DropDownList>

 <asp:SqlDataSource ID="picturesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
      SelectCommand="SELECT [PictureID], [Title], [UploadedOn] FROM [Pictures] WHERE UserId = @UserId AND 
       (CategoryID = @CategoryID Or @CategoryID IS NULL) ORDER BY UploadedOn DESC" 
        CancelSelectOnNullParameter="False">
  <SelectParameters>
      <asp:ControlParameter ControlID="categories" Name="CategoryID" PropertyName="SelectedValue"/>
      <asp:QueryStringParameter Name="UserId" QueryStringField="ID" />
  </SelectParameters>
</asp:SqlDataSource> 


<asp:GridView ID="GridView1" runat="server" DataSourceID="picturesDataSource">
</asp:GridView>

【问题讨论】:

    标签: asp.net query-string sqldatasource


    【解决方案1】:

    如果不显示页面代码或至少解释其作用,就很难回答您的问题。从 url 看来,该页面依赖于 ID 参数并尝试将其解析为 Guid。需要测试是否传递了id参数,仅在这种情况下使用:

    string id = Request["ID"];
    if (!string.IsNullOrEmpty(id))
    {
        // The ID parameter has been passed => use its value here
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-18
      • 2023-04-05
      • 2013-02-25
      • 2012-07-03
      相关资源
      最近更新 更多