Asp.net 过路询问
考虑一个页面,当页面加载时,什么也没有显示 当我在浏览器上传递查询字符串时,它会工作,如下所示:Asp.net 过路询问,asp.net,query-string,sqldatasource,Asp.net,Query String,Sqldatasource,考虑一个页面,当页面加载时,什么也没有显示 当我在浏览器上传递查询字符串时,它会工作,如下所示: http://localhost:51765/foo/foo.aspx?ID=c516f4f4-36a9-40a7-baad-d2419ea631b9 我希望它在页面加载时工作,而不是在浏览器上传递查询字符串时工作 有人能帮我吗 <asp:SqlDataSource ID="categoriesDataSource" runat="server" connectionString=
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>
--所有专辑--
如果不显示页面的代码或至少解释它的作用,就很难回答您的问题。从url来看,页面似乎依赖于ID
参数,并试图将其解析为Guid。您需要测试ID参数是否通过,并仅在这种情况下使用它:
string id = Request["ID"];
if (!string.IsNullOrEmpty(id))
{
// The ID parameter has been passed => use its value here
}