1

你好,我希望这对某人来说很容易回答。首先,我试图ListView绑定到 aDataPager并放入一个 ASP.NETUpdatePanel来为我的数据库中的记录创建一个基于 AJAX 的寻呼机。我抓起一个UpdatePanel并放置:

  1. SqlDataSource
  2. ListView- 在ItemTemplate其中包含一个ImageButton和几个其他 ASP.NET 控件
  3. DataPager

ContentTemplate. DataPager将ID分配AsyncPostbackTriggerUpdatePanel' 的触发字段中的效果非常好。

我还想在ImageButton Click活动中进行完整的回传。但是,由于ImageButton位于 内部ListView,因此UpdataPanel会导致部分回发。我尝试将 ImageButton 添加为UpdatePanel PostBackTrigger,但UpdatePanel需要控件 ID,并且不会接受,ImageButton因为它在ListView.

如何将内部元素的控件 ID 传递给它ItemTemplateListView成功地导致完整的回发?

这是我的代码:

<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 回答