updatepanel仅在第一次更新,然后不再更新

时间:2012-01-24 14:01:12

标签: asp.net gridview updatepanel

我在更新面板中使用GridView。 我有gridview生成的编辑和取消按钮。

我第一次点击编辑时,gridview编辑模板显示正常。然后,如果我单击取消,或在另一行编辑,则没有任何反应。似乎更新面板已停止工作。

如果我在没有更新面板的情况下做同样的事情,回发工作正常,gridview会做它应该做的事情(尽管它刷新整个页面非常麻烦,这就是我想使用updatepanel的原因!)

        <asp:UpdatePanel ID="upSentOrders" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:GridView ID="gvSentOrders" runat="server"
                        autogeneratecolumns="False"
                        allowpaging="false" 
                        DataKeyNames="titxn_id" 
                        AlternatingRowStyle-CssClass="gvAlternate"                  
                        CssClass="gvTable" 
                        OnRowDataBound="addSentTotals" 
                        OnRowEditing="editOrder" 
                        OnRowCancelingEdit="cancelEdit"     
                        OnDataBound="showSentTotals"                    
                        AutoGenerateEditButton="true" 
                        AutoGenerateDeleteButton="false" 
                        ShowFooter="true" 
                        ShowHeader="true">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <table class="basketHeader">
                                <tr>
                                    <td class="basketTitle"><asp:Label ID="lblTitle" runat="server" Text="Order Date" /></td>
                                    <td class="basketPX"><asp:Label ID="lblPXOffer" runat="server" Text="Part Ex" /></td>
                                    <td class="basketCash"><asp:Label ID="lblCashOffer" runat="server" Text="Cash" /></td>
                                    <td class="basketDelete">&nbsp;</td>
                                </tr>                                
                            </table>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table class="basket">
                                <tr>
                                    <td class="basketTitle"><asp:Label ID="lblTitle" runat="server" Text='<%# String.Format("{0:dd MMMM yyyy}", Eval("titxn_date")) %>' /></td>
                                    <td class="basketPX"><asp:Label ID="lblPXOfferItem" runat="server" Text='<%# "£" + Eval("titxn_totalpxatsend") %>' /></td>
                                    <td class="basketCash"><asp:Label ID="lblCashOfferItem" runat="server" Text='<%# "£" + Eval("titxn_totalcashatsend") %>' /></td>
                                    <td class="basketDelete"><asp:Button ID="btnEdit" Text="" CommandArgument="1" runat="server" CssClass="editButton" ToolTip="View Order" OnClick="viewOrder" /></td>
                                </tr>                                
                            </table>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <table class="basket">
                                <tr>
                                    <td class="basketTitle"><asp:Label ID="lblTitle" runat="server" Text='<%# String.Format("{0:dd MMMM yyyy}", Eval("titxn_date")) %>' /></td>
                                    <td class="basketPX"><asp:Label ID="lblPXOfferItem" runat="server" Text='<%# "£" + Eval("titxn_totalpxatsend") %>' /></td>
                                    <td class="basketCash"><asp:Label ID="lblCashOfferItem" runat="server" Text='<%# "£" + Eval("titxn_totalcashatsend") %>' /></td>
                                    <td class="basketDelete"><asp:Button ID="btnStopEdit" Text="" CommandArgument="-1" runat="server" CssClass="stopEditButton" ToolTip="View Order" OnClick="viewOrder" /></td>
                                </tr>                                
                                <tr>
                                    <td colspan="4">
                                        Items GridView here...
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="4">
                                        <asp:Label ID="lblAddress" runat="server" Text='<%# Eval("titxn_name") + ", " + Eval("titxn_addressnumber") + " " + Eval("titxn_addressone") + ", " + Eval("titxn_addresstown") + ", " + Eval("titxn_addresscounty") + ", " + Eval("titxn_addresscountry") + ", " + Eval("titxn_addresspostcode") + "." %>' />   
                                    </td>
                                </tr>
                            </table>                        
                        </EditItemTemplate>
                        <FooterTemplate>
                            <table class="basketTotals">
                                <tr>
                                    <td class="basketTitle">Total Still To Arrive</td>
                                    <td class="basketPX"><asp:Label ID="lblPxTotal" runat="server" Text="" /></td>
                                    <td class="basketCash"><asp:Label ID="lblCashTotal" runat="server" Text="" /></td>
                                    <td class="basketDelete">&nbsp;</td>
                                </tr>                                
                            </table>                  
                        </FooterTemplate>
                    </asp:TemplateField>
                </Columns>
                <EmptyDataTemplate>
                    <p>There is no orders still being processed.  Look like we've already completed all the orders you've sent us!</p>
                </EmptyDataTemplate>
            </asp:GridView>    
        </ContentTemplate>
    </asp:UpdatePanel>

代码背后......

protected void editOrder(object sender, GridViewEditEventArgs e)
{
    gvSentOrders.EditIndex = e.NewEditIndex;
    bindSentGridView();
}

protected void cancelEdit(object sender, GridViewCancelEditEventArgs e)
{
    gvSentOrders.EditIndex = -1;
    bindSentGridView();
}

任何想法都会有很大的帮助。 感谢。

3 个答案:

答案 0 :(得分:7)

来自另一段代码的JS错误阻止了AJAX更新面板。

答案 1 :(得分:2)

由于UpdatePanel有一个属性UpdateMode =“Conditional”,你需要在每次回发时从代码隐藏中更新它:

protected void editOrder(object sender, GridViewEditEventArgs e)
{
    gvSentOrders.EditIndex = e.NewEditIndex;
    bindSentGridView();
    upSentOrders.Update();
}

protected void cancelEdit(object sender, GridViewCancelEditEventArgs e)
{
    gvSentOrders.EditIndex = -1;
    bindSentGridView();
    upSentOrders.Update();
}

希望这有帮助。

答案 2 :(得分:0)

只是为了进行测试:

<asp:UpdatePanel ID="upSentOrders" runat="server"
                 UpdateMode="Conditional"
                 ChildrenAsTriggers="true">

确保设置GridView属性EnableSortingAndPagingCallbacks = false;