悬崖上的指纹

导航

 

前台代码:

<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();
            }
        }
    }

  

posted on 2014-04-06 13:01  悬崖上的指纹  阅读(194)  评论(0编辑  收藏  举报