• GridView双层嵌套


    前台代码:

    <div>
            <asp:GridView ID="GridViewOne" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridViewOne_RowDataBound">
                <Columns>
                    <asp:TemplateField>
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DepartName") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("DepartName") %>'></asp:Label>
                            <br />
                            <asp:GridView ID="GridViewTwo" runat="server">
                            </asp:GridView>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </div>
    

    后台代码:

    public partial class WebForm2 : System.Web.UI.Page
        {
            StaffInfoBLL sbll = new StaffInfoBLL();
            DepartmentInfoBLL dbll = new DepartmentInfoBLL();
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack) {
                    InitGridViewOne();
                }
            }
    
            private void InitGridViewOne()
            {
                this.GridViewOne.DataSource = dbll.GetAll();
                this.GridViewOne.DataBind();
            }
    
            protected void GridViewOne_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow) {
                    GridView g = e.Row.FindControl("GridViewTwo") as GridView;
                    DepartmentInfo d = e.Row.DataItem as DepartmentInfo;
                    g.DataSource = sbll.GetByDepartId(d.DepartId);
                    g.DataBind();
                }
            }
        }
    

      

  • 相关阅读:
    Java compiler level does not match the version of the installed Java Project facet.
    Project configuration is not up-to-date with pom.xml. Select: Maven->Update Project... from the project context menu or use Quick Fix.
    JavaScript
    JavaScript
    Eclipse
    Eclipse
    Oracle
    Java
    Ext JS 4.2
    Eclipse
  • 原文地址:https://www.cnblogs.com/liujie1111/p/3648435.html
Copyright © 2020-2023  润新知