UpdatePanel在Parent GridView ItemTemplate中不起作用

时间:2014-04-18 12:58:12

标签: javascript asp.net ajax sharepoint updatepanel

感谢您查看此内容。

背景 - 在我们的项目中有一个Share Point 2013 Visual Web Part。它有4个嵌套的GridViews。点击一个图像按钮后,3个网格将被展开。人口也可以通过点击该图像按钮进行编码。但是,由于背面发生了反复,页面闪烁,所有网格都收缩。因此,我决定在第二个网格的项目模板内部保留一个更新面板。

问题 - 将它放在那里后,我能够停止页面闪烁。点击上面的图片按钮,不再回复了。但是,没有显示网格。一点都不我通过评论更新面板来查看是否获取数据。是的,我正在获取数据。它正在显示。但是,一旦打开更新面板,Grids就不再显示了。

我的ASPX -

<asp:gridview runat="server" id="gvParent" width="98%" bordercolor="#00ABA4"
                        horizontalalign="Center" borderstyle="Solid" rowstyle-horizontalalign="Center"
                        selectedrowstyle-verticalalign="Middle"
                        autogeneratecolumns="False" datakeynames="Staff ID" emptydatatext="No Record Found!"
                        borderwidth="1px" allowpaging="True" pagesize="5" OnRowDataBound="gvParent_RowDataBound" OnRowCreated="gvParent_RowCreated" >

                        <Columns>
                            <asp:TemplateField>
                                         <ItemTemplate>
                                           <img alt="" style="cursor: pointer" src="../../_layouts/15/images/eTRAMS_img/plus.gif" />
                                              <asp:Panel ID="PnlClassification" runat="server" Style="display: none">

                                                         <asp:GridView ID="gvClassification" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid" Width="100%" 
                                                     HeaderStyle-HorizontalAlign="Left">
                                                     <Columns>
                                                        <asp:TemplateField HeaderStyle-HorizontalAlign="Left">
                                                             <ItemTemplate>
                                                                  <asp:ImageButton ID="ImgClassification" runat="server" ImageUrl="../../_layouts/15/images/eTRAMS_img/plus.gif"
                                                                      CommandArgument='<%# Eval("HistoryClassification") %>'></asp:ImageButton>

                                                                 <%--child Gridview--%>
                                                                 <asp:UpdatePanel ID="UpdatePanel1" ChildrenAsTriggers="false" runat="server" UpdateMode="Always">
                                                                            <ContentTemplate>
                                                                    <asp:Panel ID="pnlCurrent" runat="server" Style="display:none;">

                                                                                 <asp:GridView ID="gvCurrent" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid" Width="100%"
                                                                        HeaderStyle-HorizontalAlign="Left" DataKeyNames="TrainingName">
                                                                        <Columns>
                                                                            <asp:TemplateField HeaderText="No.">
                                                                                <ItemTemplate>
                                                                                    <asp:Label ID="Label1" runat="server"></asp:Label>
                                                                                </ItemTemplate>
                                                                            </asp:TemplateField>
                                                                            <asp:BoundField DataField="TrainingName" HeaderText="Training Title" />
                                                                            <asp:BoundField DataField="LastTrainingAttendedFrom" HeaderText="Attended Date From" />
                                                                            <asp:BoundField DataField="LastTrainingAttendedTo" HeaderText="Attended Date To" />
                                                                            <asp:BoundField DataField="Refresher" HeaderText="Remark" />
                                                                        </Columns>
                                                               </asp:GridView>                                                                               
                                                                    </asp:Panel>


                                                                    <asp:Panel ID="PnlOthers" runat="server" Style="display:none;">

                                                                                <asp:GridView ID="gvOthers" runat="server" AutoGenerateColumns="false" 
                                                                                    CssClass="ChildGrid" Width="100%" HeaderStyle-HorizontalAlign="Left" 
                                                                                    DataKeyNames="TrainingName">
                                                                        <Columns>
                                                                            <asp:TemplateField HeaderText="No.">
                                                                                <ItemTemplate>
                                                                                    <asp:Label ID="Label2" runat="server"></asp:Label>
                                                                                </ItemTemplate>
                                                                            </asp:TemplateField>
                                                                            <asp:BoundField DataField="TrainingName" HeaderText="Training Title" />
                                                                            <asp:BoundField DataField="LastTrainingAttendedFrom" HeaderText="Attended Date From" />
                                                                            <asp:BoundField DataField="LastTrainingAttendedTo" HeaderText="Attended Date To" />
                                                                        </Columns>
                                                               </asp:GridView>
                                                                        </asp:Panel>
                                                                            </ContentTemplate>
                                                                            <Triggers>
                                                                                <%--<asp:AsyncPostBackTrigger ControlID="ImgClassification" EventName="Click" />--%>
                                                                            </Triggers>
                                                                            </asp:UpdatePanel>


                                                                 <asp:Label ID="lblClassification" runat="server" Text='<%# Eval("HistoryClassification") %>' CommandName="Select"></asp:Label>

                                                             </ItemTemplate>
                                                         </asp:TemplateField>
                                                    </Columns>
                                                 </asp:GridView>                                                        
                                             </asp:Panel>
                                         </ItemTemplate>
                                         <ItemStyle Width="20px" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="No.">
                                <ItemTemplate>
                                    <asp:Label ID="Label4" runat="server"></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="Staff Name" HeaderText="Staff Name" />
                            <asp:BoundField DataField="Staff ID" HeaderText="Staff Number" />
                            <asp:BoundField DataField="Position Code" HeaderText="Position Code" />
                            <asp:BoundField DataField="Position Title" HeaderText="Position Name" />
                            <asp:BoundField DataField="Division" HeaderText="Division" />
                            <asp:BoundField DataField="Department" HeaderText="Department" />
                            <asp:BoundField DataField="Section" HeaderText="Section" />


                        </Columns>

                    </asp:gridview>

代码背后 -

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        InitializeControl();
        ScriptManager.GetCurrent(this.Page).RegisterAsyncPostBackControl(gvParent);
    }

private void ImgClassification_Click(object sender,ImageClickEventArgs e)         {             ImageButton ImgClassification =(发送者为ImageButton);             GridViewRow row =(ImgClassification.NamingContainer as GridViewRow);             if(ImgClassification.CommandArgument ==“Current”)             {                 row.FindControl(“pnlCurrent”)。Visible = true;                 ImgClassification.ImageUrl =“../../_layouts/15/images/eTRAMS_img/minus.jpg”;                 GridView gvCurrent = row.FindControl(“gvCurrent”)作为GridView;                 string strPast = ImgClassification.CommandArgument;                 getCurrentHistory(strPast,gvCurrent);

            UpdatePanel updtPnlPast = row.FindControl("UpdatePanel1") as UpdatePanel;
            updtPnlPast.Update();
        }

        if(ImgClassification.CommandArgument == "Past")
        {
            row.FindControl("PnlOthers").Visible = true;
            ImgClassification.ImageUrl = "../../_layouts/15/images/eTRAMS_img/minus.jpg";
            GridView gvOthers = row.FindControl("gvOthers") as GridView;
            string strPast = ImgClassification.CommandArgument;
            getJoinQuery(strPast, gvOthers);

            UpdatePanel updtPnlPast = row.FindControl("UpdatePanel1") as UpdatePanel;
            updtPnlPast.Update();
        }

        if (ImgClassification.CommandArgument == "Others")
        {
            row.FindControl("PnlOthers").Visible = true;
            ImgClassification.ImageUrl = "../../_layouts/15/images/eTRAMS_img/minus.jpg";
            GridView gvOthers = row.FindControl("gvOthers") as GridView;
            string strPast = ImgClassification.CommandArgument;
            getJoinQuery(strPast, gvOthers);

            UpdatePanel updtPnlPast = row.FindControl("UpdatePanel1") as UpdatePanel;
            updtPnlPast.Update();

        }
    }

我尝试了尽可能多的东西,但没有结果。你能搞清楚,我在这里缺少什么?这是停止显示网格。

1 个答案:

答案 0 :(得分:0)

最后我发现有一定的复杂性限制,可以由UpDatePanel处理,不仅限于此。对于我的场景来说,这是非常深刻的嵌套问题,所以我无法实现它。最后,我转向JQuery方法来实现我的目标,这对我来说非常好。

感谢你们每个人的支持和建议。