2009-01-16 76 views

回答

-1

GridView的相當靜態的。如果表格將變得更加複雜,我們使用XSLT,因此我們可以對其進行最終控制。否則,Microsoft提供其他ASP.NET控件,如DataRepeater。

5

當然可以,這是相當容易...

最好方法是讓一些ObjectDataSource的整個過程爲了讓你更容易,或者當然,你可以綁定GridView中的nasched gridview在paralynt gridview OnRowDataBound事件中,這一切都取決於你:)

exa mple:

<asp:GridView ID="gvGrandFather" runat="server" DataSourceID="odsGrandFather"> 
    <Columns> 
     <asp:BoundField DataField="myField1" HeaderText="myText1" /> 
     <asp:BoundField DataField="myField2" HeaderText="myText2" /> 
     <asp:BoundField DataField="myField3" HeaderText="myText3" /> 
     <asp:TemplateField> 
      <ItemTemplate> 
       <asp:GridView ID="gvFather" runat="server" DataSourceID="odsFather"> 
        <Columns> 
         <asp:BoundField DataField="myField1" HeaderText="myText1" /> 
         <asp:BoundField DataField="myField2" HeaderText="myText2" /> 
         <asp:BoundField DataField="myField3" HeaderText="myText3" /> 
         <asp:TemplateField> 
          <ItemTemplate> 
           <asp:GridView ID="gvSon" runat="server" DataSourceID="odsSon"> 
            <Columns> 
             <asp:BoundField DataField="myField1" HeaderText="myText1" /> 
             <asp:BoundField DataField="myField2" HeaderText="myText2" /> 
             <asp:BoundField DataField="myField3" HeaderText="myText3" /> 
            </Columns> 
           </asp:GridView> 
          </ItemTemplate> 
         </asp:TemplateField> 
        </Columns> 
       </asp:GridView> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

<asp:ObjectDataSource ID="odsGrandFather" runat="server" DataObjectTypeName="Company" TypeName="CompanyDAO" SelectMethod="FindAll" /> 
<asp:ObjectDataSource ID="odsFather" runat="server" DataObjectTypeName="Employees" TypeName="EmployeesDAO" SelectMethod="FindByID"> 
    <SelectParameters> 
     <asp:Parameter Name="myFieldInCompanyObject" Type="String" /> 
    </SelectParameters> 
</asp:ObjectDataSource> 
<asp:ObjectDataSource ID="odsSon" runat="server" DataObjectTypeName="Person"TypeName="PersonsDAO" SelectMethod="FindByID"> 
    <SelectParameters> 
     <asp:Parameter Name="myFieldInEmployeesObject" Type="String" /> 
    </SelectParameters> 
</asp:ObjectDataSource> 

假設你有一個像

Company 
    Field1 
    Field2 
    Field3 
    Employees witch is List<Person> 
    Field1 
    Field2 
    Field3 
    Person witch is List<Person> 
     Field1 
     Field2 
     Field3 

您的公司對象所有你需要做的是爲每個DAO和返回列表或類似

public class CompanyDAO 
{ 
    private List<Company> Companies 
    { 
     get 
     { 
      List<Company> companies = HttpContext.Current.Session["Companies"] as List<Company>; 
      if (companies == null) 
       companies = new List<Company>(); 
      return companies; 
     } 
    } 
    public CompanyDAO() { } 

    [DataObjectMethod(DataObjectMethodType.Select)] 
    public IEnumerable<Company> FindAll() 
    { 
     return this.Companies; 
    } 

    [DataObjectMethod(DataObjectMethodType.Select)] 
    public IEnumerable<Company> FindByID(String CompanyID) 
    { 
     return (from c in this.Companies where c.ID == CompanyID select c).ToList(); 
    } 
} 

對象本身希望它有助於看到在隧道盡頭的光;)

+0

這是否會得到執行父行下的子行?我不希望孩子網格在父行相同的行,但在父行。 – renegadeMind 2009-01-16 12:35:32

0

這個 01的好文章 它使用ASP.NET AJAX和AJAX控件工具包,使其可摺疊。

相關問題