您好我正在尝试创建一个SQLDataSource,其参数具有查询字符串的值,但我不断收到错误消息:
PropertyName必须设置为ControlParameter'SubcategoryId'中名为'ListOfPosts'的控件的有效属性名称
我似乎无法理解propertyName应该是什么。这是我的代码:
<asp:SqlDataSource ID="ListOfPosts" runat="server"
ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [forum_posts].[PostTitle], [forum_posts].[PostContent], [forum_posts].[PostDate],
aspnet_Users.Username , forum_subcategories.SubCategoryName
FROM [forum_posts]
JOIN aspnet_Users ON [forum_posts].UserId = aspnet_Users.UserId
JOIN forum_subcategories on forum_posts.SubcategoryId = forum_subcategories.SubCategoryID
WHERE [forum_posts].SubcategoryId = @SubcategoryId">
<SelectParameters>
<asp:ControlParameter Name="SubcategoryId" ControlID="ListOfPosts" Type="String" DefaultValue='<%= Request.QueryString["post"] %>'/>
</SelectParameters>
</asp:SqlDataSource>
答案 0 :(得分:1)
您可以使用asp:QueryStringParameter
代替。 asp:ControlParameter
旨在与您网页中的控件一起使用,如果此类控件不存在,您将收到错误
<SelectParameters>
<asp:QueryStringParameter Name="SubcategoryId" Type="String" querystringfield="post"/>
</SelectParameters>
其他人是ControlParameter, CookieParameter, FormParameter, ProfileParameter, SessionParameter