2015-04-19 121 views
-3

我有一個嵌套GridView 4級, 當我點擊「+」顯示子GridView我向數據庫請求數據庫下載當前行的數據,每件事情對我來說很好,唯一的問題我必須是在設計,所有的GridView 其父欄子GridView控件顯示,這是它的外觀:顯示嵌套gridview

家長的GridView enter image description here

第一個孩子的GridView enter image description here

這裏是我的aspx代碼:

<asp:UpdatePanel ID="upNestedGridView" runat="server" UpdateMode="Conditional"> 
     <ContentTemplate> 
      <asp:GridView ID="gvCostCenters" runat="server" ....> 
      <Columns> 
      <asp:TemplateField> 
       <ItemTemplate> 
       <asp:ImageButton ID="imgShowAccountingPlan" runat="server" OnClick="Show_Hide_AccountingPlansGrid" .../> 
        <asp:Panel ID="pnlAccountingPlan" runat="server" Visible="false" Style="position: relative"> 
         <asp:GridView ID="gvAccountingPlans" runat="server" AutoGenerateColumns="false"...."> 
          <Columns> 
          <asp:TemplateField>         
           <ItemTemplate> 
            <asp:ImageButton ID="imgShowPrograms" runat="server" OnClick="Show_Hide_ProgramsGrid" .../> 
            <asp:Panel ID="pnlPrograms" runat="server" Visible="false" Style="position: relative"> 
             <asp:GridView ID="gvPrograms" runat="server" AutoGenerateColumns="false" ...> 
              <Columns> 
               <asp:TemplateField> 
                <ItemTemplate> 
                 <asp:ImageButton ID="imgShowProjects" runat="server" OnClick="Show_Hide_ProjectsGrid" ..../> 
                 <asp:Panel ID="pnlProjects" runat="server" Visible="false" Style="position: relative"> 
                  <asp:GridView ID="gvProject" runat="server" ....> 
                   ..... 
                  </asp:GridView> 
                 </asp:Panel> 
                </ItemTemplate> 
               </asp:TemplateField>                    
               <asp:BoundField DataField="Label" HeaderText="البند " ItemStyle-HorizontalAlign="Right" /> 
               .... 
              </Columns> 
             </asp:GridView> 
            </asp:Panel> 
           </ItemTemplate> 
          </asp:TemplateField>               
          <asp:BoundField DataField="NumAccountingPlan" HeaderText="الخطة المحاسبية " ItemStyle-HorizontalAlign="Right" /> 
          ... 
         </Columns> 
        </asp:GridView> 
       </asp:Panel> 
      </ItemTemplate> 
     </asp:TemplateField> 
     ... 
     <asp:BoundField DataField="OperatingExpenses" HeaderText="المصروفات التشغيلية" DataFormatString="{0:#,##0.00;(#,##0.00);0}" /> 
    </Columns> 
</asp:GridView> 

我jQuery代碼:

<script type="text/javascript"> 
    $(function() { 
     $("[src*=minus]").each(function() { 
      $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>"); 
      $(this).next().remove() 
     }); 
    }); 
</script> 

我的代碼C#:

protected void Show_Hide_AccountingPlansGrid(object sender, EventArgs e) 
    { 
     try 
     { 
      ServiceClass service = new ServiceClass(); 
      ImageButton imgShowHide = (sender as ImageButton); 
      GridViewRow row = (imgShowHide.NamingContainer as GridViewRow); 
      if (imgShowHide.CommandArgument == "Show") 
      { 

       _budget = service.GetBudgetById(int.Parse(hfIdBudget.Value)); 
       row.FindControl("pnlAccountingPlan").Visible = true; 
       imgShowHide.CommandArgument = "Hide"; 
       imgShowHide.ImageUrl = "/Content/img/minus.gif"; 
       string idCostCenter = gvCostCenters.DataKeys[row.RowIndex].Value.ToString(); 
       GridView gvAccountingPlans = row.FindControl("gvAccountingPlans") as GridView; 
       //gvAccountingPlans.ToolTip = costCenterId; 
       gvAccountingPlans.DataSource = AccountingPlanData(int.Parse(hfIdUser.Value), int.Parse(hfIdBudget.Value), int.Parse(idCostCenter)); 
       gvAccountingPlans.DataBind(); 

      } 
      else 
      { 
       row.FindControl("pnlAccountingPlan").Visible = false; 
       imgShowHide.CommandArgument = "Show"; 
       imgShowHide.ImageUrl = "/Content/img/plus.gif"; 
      } 
     } 
     catch (Exception ex) { GlobalHelpers.Trace(ex); } 
    } 

我注意到,當我刪除的UpdatePanel的第一個孩子GridView顯示效果很好,但其他人沒有。 我該如何顯示所有childs GridView?

我爲我的英語不好

+0

可以請您解決您的aspx的格式請注意......人們不會想要一路向右滾動只是爲了嘗試遵循你所擁有的或者你正在嘗試做的事情。 – MethodMan

+0

這個問題有什麼不對?它不清楚還是沒有用? –

回答

0

代碼的ASP遺憾:

<asp:UpdatePanel ID="upNestedGridView" runat="server" UpdateMode="Conditional"> 
    <ContentTemplate> 
    <asp:GridView ID="gvCostCenters" runat="server" AutoGenerateColumns="false" ....> 
     <Columns> 
     <asp:TemplateField> 
      <ItemTemplate> 
      <asp:ImageButton ID="imgShowAccountingPlan" runat="server" OnClick="Show_Hide_AccountingPlansGrid" ImageUrl="/Content/img/plus.gif" CommandArgument="Show" />              
      </ItemTemplate> 
      </asp:TemplateField>           
      .... 
      <asp:TemplateField> 
      <ItemTemplate> 
      <tr visible="false" runat="server" id="trAccountingPlan"> 
       <td visible="false" runat="server" id="tdAccountingPlan2"></td> 
       <td colspan="999" visible="false" runat="server" id="tdAccountingPlan"> 

       <asp:GridView ID="gvAccountingPlans" runat="server" ....> 
       <Columns> 
       .....            
       </Columns> 
      </asp:GridView>     
      </td> 
      </tr> 
     </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
    </asp:GridView> 
</ContentTemplate> 

代碼C#:

protected void Show_Hide_AccountingPlansGrid(object sender, EventArgs e) 
    { 
     try 
     { 

      ImageButton imgShowHide = (sender as ImageButton); 
      GridViewRow row = (imgShowHide.NamingContainer as GridViewRow); 
      if (imgShowHide.CommandArgument == "Show") 
      { 
      ... 
       imgShowHide.CommandArgument = "Hide"; 
       imgShowHide.ImageUrl = "/Content/img/minus.gif"; 
       row.FindControl("trAccountingPlan").Visible = true; 
       HtmlTableCell tdAccountingPlan = (HtmlTableCell)row.FindControl("tdAccountingPlan"); 
       HtmlTableCell tdAccountingPlan2 = (HtmlTableCell)row.FindControl("tdAccountingPlan2"); 
       tdAccountingPlan2.Visible = true; 
       tdAccountingPlan.Visible = true; 

       ... 

      } 
      else 
      {      
       imgShowHide.CommandArgument = "Show"; 
       imgShowHide.ImageUrl = "/Content/img/plus.gif"; 
       row.FindControl("trAccountingPlan").Visible = false; 
       HtmlTableCell tdAccountingPlan = (HtmlTableCell)row.FindControl("tdAccountingPlan"); 
       HtmlTableCell tdAccountingPlan2 = (HtmlTableCell)row.FindControl("tdAccountingPlan2"); 
       tdAccountingPlan2.Visible = false; 
       tdAccountingPlan.Visible = false; 
      } 
     } 
     catch (Exception ex) { GlobalHelpers.Trace(ex); } 
    }