0

ListViewで使用しているDataPagerコントロールがあり、ページが読み込まれると、ページャーに最初、次、最後、前、および10ページが表示されますが、ページのボタンまたはハイパーリンクのいずれかをクリックしても何も起こりません。何度クリックしてもかまいません。preredenderで何かをしなければならないと聞きましたが、これがどのように機能するかについてのコードは見ていません。それが解決策であり、データページャーを機能させる方法ではない場合、誰かが私がプリレンダーに入れることになっているコード(およびプリレンダーを呼び出す方法)を教えてもらえますか?

<asp:UpdatePanel ID="upSearchResults" runat="server">
    <ContentTemplate>

        <asp:Label ID="lblErrorMSG" CssClass="ErrorText" runat="server" />

        <asp:Panel ID="plSearchResults" runat="server">
            <table  style="width: 100%" border="1">
                <tr>
                    <td>
                        <asp:Literal ID="lblTitleRow" runat="server" />
                    </td>
                    <td>
                        <asp:Literal ID="lblDescriptionRow" runat="server" />
                    </td>
                    <td class="TableSelectButton">
                        <asp:Button ID="btnAddNewItem" Text="Select" runat="server" />
                    </td>
                </tr>

                <asp:ListView ID="lvSearchResults"  runat="server">

                    <LayoutTemplate>
                        <tr id="itemPlaceHolder" runat="server" />
                    </LayoutTemplate>

                    <ItemTemplate>
                        <tr>
                            <td>
                                <%#Eval("Title")%>
                            </td>
                            <td>
                                <%#Eval("Descript")%>
                            </td>
                            <td class="TableSelectButton">
                                <asp:Button ID="btnEditItem" Text="Select" PostBackUrl='<%#String.Format("{0}.aspx?ID={1}&SectionID={2}", Eval("PageName"), Eval("ID"), ddlMediaTitle.SelectedValue.ToString())%>' runat="server" />
                            </td>
                        </tr>
                    </ItemTemplate>

                </asp:ListView>
            </table>
        </asp:Panel>

        <div class="Center">
            <asp:DataPager ID="dpSearchResults" PagedControlID="lvSearchResults" PageSize="10" runat="server"> 
                <Fields> 
                    <asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="false" ShowFirstPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="true" /> 
                    <asp:NumericPagerField ButtonCount="10" /> 
                    <asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="true" ShowFirstPageButton="false" ShowLastPageButton="true" ShowPreviousPageButton="false" /> 
                </Fields> 
            </asp:DataPager>
        </div>

    </ContentTemplate>

    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
    </Triggers>

</asp:UpdatePanel>
4

3 に答える 3

2

2つのことを行うことで、コードサンプルを機能させることができました。最初にリストビューコントロールでOnPagePropertiesChangedイベントを追加し、データを再度バインドしました。

<asp:ListView ID="lvSearchResults"  runat="server" 
    OnPagePropertiesChanged="lvSearchResults_PagePropertiesChanged">

背後にあるコード:

protected void lvSearchResults_PagePropertiesChanged(object sender, EventArgs e)
{
    //bind the lvSearchResults
}

更新パネルを機能させるために、代わりにこのトリガーを使用しました。

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="lvSearchResults"
        EventName="PagePropertiesChanged" />
</Triggers>

私が持っている1つの推奨事項は、すべてが機能した後、更新パネルを完全に最後に追加することです。それらは多くの問題を隠し、解決をより困難にしているようです。

楽しみ!

于 2012-09-11T03:33:23.470 に答える
0

リストビューコントロールは、更新パネルコントロール内では使用できない既知のコントロールの1つであると確信しています。更新パネルタグを一時的に削除して、これをテストします。

于 2012-09-11T02:18:06.123 に答える
0

リストビューデータがplSearchResults.DataSource=。???を使用してプログラムでファイリングされている場合。、それであなたのページのすべてのポストバックと呼ばれます...非同期のものを含みます。

また、DataSourceオブジェクトには、ページャーコールバックが実装されている必要があります。

だからあなたのための解決策。(私が正しく仮定している場合)は次のとおりです。次のようなコードに行を追加します。

if(!isPostBack) //This line will assure tha the binding will be filled just once
    plSearchResults.DataSource = .???. 

その後、すべてのポストバックが再バインドされるわけではありません...そして、ページングのコールバックがDataSourceオブジェクトに実装されていることを確認してください

SQLDataSource、LinqDataSource、EntitiesDataSourceなどのAsp.NETデータソースオブジェクトには、すべてページングが実装されています。プログラムで1つのデータソースを作成する場合は、ページングコールバックを実装する必要があります。

于 2012-09-11T03:25:50.470 に答える