我发现很少有事情像试图在不同的内容控件中找到我的 ASP .NET 控件一样令人沮丧。对于布局,我需要将 ListView 放置在一个内容控件中,将 DataPager 和 ObjectDataSource 放置在不同的内容控件中。
<asp:Content ID="cPagedContent" ContentPlaceHolderID="cphPagedContent" runat="Server">
<asp:MultiView ID="mvPagedContent" runat="server">
<asp:View ID="mvPagedContentDefault" runat="server">
<asp:ListView ID="lvPagedContent" runat="server" ItemPlaceholderID="itemPlaceholder">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<div class="hp-post-even">
<h2>
<a href="<%# Eval("QuickLink") %>">
<%# Eval("Title") %></a></h2>
<p>
<%# Eval("Html") %></p>
</div>
</ItemTemplate>
<AlternatingItemTemplate>
<div class="hp-post">
<h2>
<a href="<%# Eval("QuickLink") %>">
<%# Eval("Title") %></a></h2>
<p>
<%# Eval("Html") %></p>
</div>
</AlternatingItemTemplate>
</asp:ListView>
</asp:View>
<asp:View ID="mvPagedContentTaxonomy" runat="server">
</asp:View>
<asp:View ID="mvPagedContentSearch" runat="server">
</asp:View>
</asp:MultiView>
</asp:Content>
<asp:Content ID="cAboveFooter" ContentPlaceHolderID="cphAboveFooter" runat="Server">
<asp:MultiView ID="mvPager" runat="server">
<asp:View ID="mvPagerDefault" runat="server">
<asp:DataPager ID="dpContentPager" runat="server"
PageSize="6">
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" FirstPageText="[First]" PreviousPageText="[Prev]"
ShowNextPageButton="false" ShowLastPageButton="false" RenderDisabledButtonsAsLabels="true"
ShowFirstPageButton="true" />
<asp:NumericPagerField ButtonCount="4" />
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" ShowPreviousPageButton="false"
NextPageText="[Next]" LastPageText="[Last]" RenderDisabledButtonsAsLabels="true"
ShowLastPageButton="true" />
</Fields>
</asp:DataPager>
<asp:ObjectDataSource ID="odsContent" runat="server" EnablePaging="true" MaximumRowsParameterName="maximumRows"
SelectCountMethod="GetContentCount" SelectMethod="GetContent" StartRowIndexParameterName="startRowIndex" />
</asp:View>
<asp:View ID="mvPagerTaxonomy" runat="server">
</asp:View>
</asp:MultiView>
</asp:Content>
在我的 C# 文件中,我可以找到 ListView 控件。但我似乎找不到与 ListView 关联的 DataPager 和 ObjectDataSource。
这是 Page_Load 的一个片段。
ListView listView;
ObjectDataSource objectDataSource;
DataPager dataPager;
listView = mvPagedContentDefault.Controls[0].FindControl("lvPagedContent") as ListView;
objectDataSource = mvPagerDefault.Controls[0].FindControl("odsContent") as ObjectDataSource;
objectDataSource.TypeName = this.GetType().AssemblyQualifiedName;
listView.DataSourceID = objectDataSource.ID;
dataPager = mvPagerDefault.Controls[0].FindControl("dpContentPager") as DataPager;
dataPager.PagedControlID = listView.ID;
关于如何找到这些吸盘的任何想法?这让我有点发疯。