简体   繁体   English

数据绑定转发器控件时,代码隐藏挂起

[英]Code-behind hangs when data binding Repeater control

I'm working on a web form in ASP.NET 4, and I need to display a long list of entries in a table based on a selection made in a drop down list. 我正在使用ASP.NET 4中的Web表单,并且需要根据下拉列表中的选择在表中显示一长列条目。 I have the following ASPX and code-behind: 我有以下ASPX和隐藏的代码:

<form method="post" runat="server" >
    <asp:ScriptManager runat="server" ID="mScriptManager"></asp:ScriptManager>
    <asp:UpdatePanel ID="pnlLocalizationInfo" runat="server" >
        <ContentTemplate>
            <div id="selectLanguage">
                <p>Pick language
                    <asp:DropDownList ID="ddllanguage" runat="server" OnTextChanged="SelectLanguage" AutoPostBack="true" />
                </p>
            </div>
            <div id="languageTable">
        <asp:Repeater id="repTable" runat="server" OnItemDataBound="AddTableData" >
            <HeaderTemplate>
            Language: 
            <asp:Label ID="lbllanguageTable" runat="server" />
            <table>
                <tr>
                    <th>Name</th>
                    <th>Value</th>
                </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:Label ID="lbltableNameLocalization" runat="server" />
                        <asp:HiddenField ID="hfnameLocalization" runat="server" Value='<%#((Localization)Container.DataItem).Id %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="txttableValueLocalization" runat="server" />
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
            </table>
            </FooterTemplate>
        </asp:Repeater>
        <asp:Button ID="btnupdateLocalization" runat="server" OnClick="UpdateLocalization" Text="Save" />           
            </div>                
        </ContentTemplate>
    </asp:UpdatePanel>
</form>

public void SelectLanguage(object sender, EventArgs e)
{
    string lang = ddllanguage.SelectedValue;
    if (ddllanguage.SelectedIndex != 0)
    {
        repTable.DataSource = Data.GetAllLocalizations(lang);
        repTable.DataBind();
    }
}

The call GetAllLocalizations returns an ArrayList with database entities that are later used to populate the Repeater table. 调用GetAllLocalizations返回带有数据库实体的ArrayList,该数据库实体以后将用于填充Repeater表。 However, the DataBind function hangs upon calling, so the entire form stops working whenever the drop down list is changed. 但是, DataBind函数在调用时挂起,因此,只要更改下拉列表,整个表单就会停止工作。 If the data binding is done on page load and not in an event handler, it works fine. 如果数据绑定是在页面加载时完成的,而不是在事件处理程序中完成的,则它将正常工作。 I have another, older page that uses this same method though (data bind in event handler of a drop down list) and it works without a hitch. 我还有另一个较旧的页面,尽管使用了相同的方法(数据绑定在下拉列表的事件处理程序中),并且工作顺利。

Any ideas? 有任何想法吗?

我看到您调用OnItemDataBound ,我将检查此事件,可能是有些过程需要时间才能完成,或者可能处于无限循环中。

I would agree with Jekom to an extent. 我会在一定程度上同意杰科姆的观点。

Also can you not just display the database results directly? 您还不能直接显示数据库结果? why are they being passed into an array first? 为什么先将它们传递到数组中?

I find when working with repeaters or any data display is to create stored procedures or functions in SQL and allow the server to do the work. 我发现在使用中继器或任何数据显示时,都是在SQL中创建存储过程或函数并允许服务器完成工作。

The reason you may have difficulty the way you are doing it is you are asking the client to work out all the information and you say there is a vast array of data to go through. 您在执行操作时可能会遇到困难的原因是,您正在要求客户计算所有信息,并且您说需要处理大量数据。

Its hard to be more specific without more information 没有更多信息,很难更具体

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM