2010-10-16 213 views
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> 

回答

2

如果不顯示頁面代碼或至少說明它的作用,很難回答您的問題。從網址看來,頁面依賴於ID參數並嘗試將其解析爲Guid。您需要測試是否傳遞ID參數並僅在此情況下使用它:

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

這裏是代碼 – onfire4JesusCollins 2010-10-16 17:14:14

相關問題