开发者

Paging for Listview inside a Gridview not working

I have a listview nested inside a gridview.

I'm trying to get paging working on the listview. I thought that it would display the paging controls, and just page through them normally.

It does display the controls, and limits the result set shown to the appropriate number of records (pageSize) but when I click on the paging controls the grid refreshes and nothing changes with the nested listview (it's still on the first page).

I've tried nesting the listview inside an updatepanel, but the behavior remains. The gridview itself is already in an updatepanel.

So this is the layout I've got:

<Gridview ID="gvApplications" DataSourceID="odsApplications" DataKeyNames="ID" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Functions">
                 <ItemTemplate>
                     <asp:ListView ID="lvFunctions" runat="server" DataSource='<%#Eval("ApplicationFunctions") %>'
                      DataKeyNames="ID">
                     <LayoutTemplate>
                         <asp:DataPager ID="dpFunctions" runat="server" PageSize="1" PagedControlID="lvFunctions">
                            <Fields>
                                <asp:NextPreviousPagerField />
                            </Fields>
                         </asp:DataPager>
                         <ul>
                         <li>
                            <span ID="itemPlaceholder" runat="server" />
                         </li>
                         </ul>
                     </LayoutTemplate>
                     <ItemTemplate>
 开发者_JS百科                       <asp:Label ID="lblFunction" runat="server" Text='<%# Eval("ApplicationFunction.Name") %>' />
                     </ItemTemplate>
                     </asp:ListView>
                 </ItemTemplate>
            </asp:TemplateField>
</Columns>
</Gridview>

Ideas?


Honestly, I would consider using a master-details pattern here. There are a lot of code examples on this. For example:

Google: Master Details Examples with Child Objects

There are also scenarios where the details view (child objects in your case) would display on a separate page. Either way, by displaying the child objects in a separate details view, you avoid the coding and display issues that come with nesting.

Matt Berseth has some of the best code examples out there on this topic:

http://mattberseth.com/blog/gridview/


Listview / datapager combination do not work properly if the listview does not use a datasource control.

Try including a datasource control (objectdatasource could be applicable) in the template field.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜