1

こんにちは、誰かが簡単に答えられることを願っています。最初に、ASP.NETにListViewバインドして、データベースのレコード用に AJAX を利用したページャーを作成しようとしていました。をつかんで配置しました:DataPagerUpdatePanelUpdatePanel

  1. SqlDataSource
  2. ListView- 1 つまたは複数の他の ASP.NET コントロールをItemTemplate含めるImageButton
  3. DataPager

ContentTemplate。のトリガー フィールドにDataPagerID を割り当てると、完全に機能しました。AsyncPostbackTriggerUpdatePanel

また、イベントで完全なポストバックを実行したいと考えていましたImageButton Click。ただし、ImageButtonは の内部にあるためListViewUpdataPanelによって部分的なポストバックが発生します。ImageButton を として追加しようとしましたUpdatePanel PostBackTriggerが、はコントロール ID を要求し、 の中にあるためUpdatePanelを受け入れません。ImageButtonListView

ItemTemplate内の要素のコントロール ID を渡してListView、完全なポスト バックを正常に発生させるにはどうすればよいですか?

これが私のコードです:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate> 
        <asp:SqlDataSource ... ></asp:SqlDataSource>
        <asp:ListView ID="ListViewForAlbums" runat="server" >
            <ItemTemplate>
                <div class="album">
                    <asp:ImageButton ID="albumPhoto" class="albumPhotosStyle" runat="server" ImageUrl="<%# Bind('albumPhotoPath') %>" AlternateText="<%# Bind('album_id') %>" ToolTip="<%# Bind('albumDetails') %>" onclick="albumPhotos_Click"  />
                    <div class="albumInfoHolder">

                    ...

                    </div>
                </div> <!-- End Album -->
            </ItemTemplate>
            <EmptyDataTemplate>
                <p>No Albums Yet. Check Back Soon!</p>
            </EmptyDataTemplate>
        </asp:ListView>

        <asp:DataPager ID="DataPagerForAlbums" runat="server" PagedControlID="ListViewForAlbums" PageSize="3" >
            <Fields>
                <asp:NextPreviousPagerField ShowFirstPageButton="True" FirstPageText="&laquo" ShowNextPageButton="False"  ShowPreviousPageButton="false" />
                <asp:NumericPagerField />
                <asp:NextPreviousPagerField ShowLastPageButton="True" LastPageText="&raquo" ShowPreviousPageButton="False"  ShowNextPageButton="false" />
            </Fields>
        </asp:DataPager>
        </p>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="DataPagerForAlbums" />
    </Triggers>
</asp:UpdatePanel> 
4

2 に答える 2

2

ScriptManagerを使用して、コントロールをポストバックコントロールとして登録できます。ItemDataBoundイベントで次のようなことを行います。

protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
    ImageButton button = e.Item.FindControl("ImageButton1") as ImageButton;
    if (button != null)
    {
        ScriptManager.GetCurrent(Page).RegisterPostBackControl(button);            
    }
}
于 2011-10-26T19:30:52.960 に答える
0

ItemDataBound ListView のイベントを使用して ImageButton を取得し、ScriptManager の RegisterPostBackControl メソッドでポストバック コントロールとして登録します。

于 2011-10-26T19:23:30.013 に答える