这是我的SQL数据库中的数据表,下面是我的Repeater控件的代码:
ArticleID int NOT NULL,
ArticleTitle varchar(100) NOT NULL,
ArticleCategory int NOT NULL,
ArticleDate datetime NOT NULL,
ArticleContent text NOT NULL,
DeletedYN char(3) NOT NULL
<asp:Repeater runat="server" ID="rptArticles" DataSourceID="dsLatestArticles">
<HeaderTemplate>
<span class="title"><%#Container.DataItem("ArticleTitle")%></span><br />
<span class="title3">Posted On: <%#Container.DataItem("ArticleDate")%></span>
</HeaderTemplate>
<ItemTemplate><p><%#Container.DataItem("ArticleContent")%></p></ItemTemplate>
<FooterTemplate>
<p class="RightAlign"><a href="/Articles/Read.aspx?i=<%#Container.DataItem("ArticleID") %>">Read more...</a></p>
</FooterTemplate>
</asp:Repeater>
当我尝试加载此页面时,我收到错误消息Object variable or With block variable not set.
作为参考,我的SqlDataSource配置如下:
<asp:SqlDataSource ID="dsLatestArticles" runat="server"
ConnectionString="<%$ ConnectionStrings:VBSiteConnectionString %>"
SelectCommand="SELECT [ArticleID], [ArticleTitle], [ArticleDate], [ArticleContent] FROM [Articles] WHERE ([DeletedYN] = @DeletedYN)">
<SelectParameters>
<asp:Parameter DefaultValue="No" Name="DeletedYN" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
我不知道我在这里做错了什么,有谁能看到问题? 如需进一步参考,请参阅我的Stack Trace:
[NullReferenceException: Object variable or With block variable not set.]
Microsoft.VisualBasic.CompilerServices.Container..ctor(Object Instance) +510276
Microsoft.VisualBasic.CompilerServices.NewLateBinding.InternalLateIndexGet(Object Instance, Object[] Arguments, String[] ArgumentNames, Boolean ReportErrors, ResolutionFailure& Failure) +88
Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateIndexGet(Object Instance, Object[] Arguments, String[] ArgumentNames) +21
ASP.default_aspx.__DataBind__control3(Object sender, EventArgs e) in D:\Development\Projects\Web\LogansArchive\Default.aspx:9
System.Web.UI.Control.OnDataBinding(EventArgs e) +99
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +124
System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +323
System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +51
System.Web.UI.WebControls.Repeater.DataBind() +75
System.Web.UI.WebControls.Repeater.EnsureDataBound() +55
System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +15
System.Web.UI.Control.PreRenderRecursiveInternal() +80
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
提前致谢!
答案 0 :(得分:0)
如果其他人遇到此问题,这是我找到的解决方案
原因
我在我的Repeater控件的<HeaderTemplate>
部分从我的SqlDataSource中提取数据。
这就是造成这个问题的原因。我不确定为什么,但重点是这样做是行不通的。
解决方案
所有数据检索(即<%#Container.DataItem("Field1") %>
阻止)必须才能在Repeater控件的<ItemTemplate>
部分中使用。