Repeater中的UpdatePanel

时间:2011-03-28 11:53:47

标签: c# asp.net updatepanel repeater

在我的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#-code

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,难怪它没有显示。

1 个答案:

答案 0 :(得分:2)

可能是因为你必须明确设置异步绑定

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

</asp:UpdatePanel>
相关问题