【问题标题】:UpdatePanel inside Repeater中继器内的 UpdatePanel
【发布时间】:2011-03-28 11:53:46
【问题描述】:

在我的 UserControl 中,我尝试像这样更新中继器内的更新面板:

HTML 标记

<asp:UpdatePanel ID="updDocumentQuickView" runat="server" UpdateMode="Conditional">
  <ContentTemplate>
    <asp:Repeater ID="repFolders" runat="server" OnItemDataBound="repFolders_OnItemDataBound" OnItemCommand="repFolders_OnItemCommand">
        <ItemTemplate>

            <asp:LinkButton ID="lnkFolder" runat="server"></asp:LinkButton>  

            <asp:UpdatePanel ID="updFiles" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Repeater ID="repFiles" runat="server" OnItemDataBound="repFiles_OnItemDataBound">
                        <ItemTemplate>
                            <%# Container.DataItem %> 
                        </ItemTemplate>                             
                    </asp:Repeater>   
                </ContentTemplate>                
            </asp:UpdatePanel>
        </ItemTemplate>        
    </asp:Repeater>
  </ContentTemplate>
</asp:UpdatePanel>

C#-代码

protected void repFolders_OnItemCommand(object sender, CommandEventArgs e)
{  
    int intRow = -1;

    ScriptManager myScriptManager = (ScriptManager)Page.Master.FindControl("myScriptManager");

    Match myMatch = Regex.Match(myScriptManager.AsyncPostBackSourceElementID, "repFolders.ctl([0-9]*).lnkFolder");

    if (myMatch != null)        
        intRow = Convert.ToInt32(myMatch.Groups[1].Value);

    if (intRow > -1)
    {
        RepeaterItem myItem = repFolders.Items[intRow];

        Repeater repFiles = (Repeater)myItem.FindControl("repFiles");
        UpdatePanel updFiles = (UpdatePanel)myItem.FindControl("updFiles");

        string[] arr1 = new string[] { 
                                    "array item 1", 
                                    "array item 2", 
                                    "array item 3", 
                                    "array item 4", 
                                    "array item 5" };

        repFiles.DataSource = arr1;
        repFiles.DataBind();

        updFiles.Update();
    }
}

我得到的最终结果是 updDocumentQuickView 是更新的 UpdatePanel,而不是 updFiles。如果我在 lnkFolder 周围包装了一个 UpdatePanel,那么该 UpdatePanel 将使用相同的 C# 代码进行更新。我检查了用 fiddler 发回的数据类型,并发送了错误的 UpdatePanel。我得到了正确的RepeaterItem,并且找到了repFiles 和updFiles。为了获得正确的 UpdatePanel 以进行更新,我错过了什么?

更新

Hawxby 解决方案解决了 updDocumentQuickView 更新的问题,谢谢。但是我仍然遇到 updFiles 什么都不发回的问题。一些进一步的测试,将文字放入 updFiles 并工作,告诉我 repFiles 有一些东西没有返回。 repFiles 确实有有界的数据。

最终解决方案

repFolders_OnItemDataBound 中的repFiles.Visible 设置为false,难怪没有显示。

【问题讨论】:

    标签: c# asp.net updatepanel repeater


    【解决方案1】:

    这可能是因为您必须显式设置异步绑定

    <asp:UpdatePanel ID="updDocumentQuickView" ChildrenAsTriggers="false">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="repFolders" EventName="repFolders_OnItemCommand" />
        </Triggers>
    
    </asp:UpdatePanel>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-05
      • 2013-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多