就是我定义了一个用户控件user.ascx,怎样在Table服务器控件下动态添加user.ascx

解决方案 »

  1.   

    可以在一个GridView的TemplateField里放一个PlaceHolder,然后在GridView.RowDataBound事件处理代码里
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        PlaceHolder holder = (PlaceHolder)e.Row.FindControl("PlaceHolder1");
        Control ctrl = Page.LoadControl("~/UserControl.ascx");
        holder.Controls.Add(ctrl);
    }类似这种方式添加用户控件。不过有个最重要的地方:把GridView的EnableViewState设为false;至于<table runat="server">里添加也应该是可以的。