传递查询字符串

发布于 2024-09-27 10:05:01 字数 1754 浏览 4 评论 0原文

考虑一个页面,当页面加载时,没有任何内容显示。

当我在浏览器上传递查询字符串时,它会起作用,如下所示:

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>

Consider a page, when the page loads, nothing shows up.

It works when i pass the querystring on the browser as this:

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

I want it to work when the page load not when i pass the querystring on the browser.

Can someone help me with this?

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

农村范ル 2024-10-04 10:05:01

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

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

It is difficult to answer your question without showing the code of the page or at least explaining what it does. From the url it seems that the page relies on the ID parameter and tries to parse it to a Guid. You need to test whether the ID parameter is passed and use it only in this case:

string id = Request["ID"];
if (!string.IsNullOrEmpty(id))
{
    // The ID parameter has been passed => use its value here
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文