日期:2014-05-18  浏览次数:20457 次

如何保持Controls.add()的控件的状态?
我通过后台代码动态的向前台添加了控件,代码如下:
                ds   =   DbTools.getDataSetBySQL( "select   distinct   substring(inform_type,1,1)   inform_type_order_id   from   dim_inform_type   order   by   1 ");
                GV_inform.DataSource   =   ds;
                GV_inform.DataBind();
                foreach   (GridViewRow   row   in   GV_inform.Rows)
                {
                        PlaceHolder   PH_content   =   (PlaceHolder)row.FindControl( "PH_content ");
                        string   inform_type_order_id   =   ((ITextControl)row.FindControl( "L_inform_type_order_id ")).Text;
                        ds   =   DbTools.getDataSetBySQL( "select   *   from   dim_inform_type   where   inform_type   like   ' "   +   inform_type_order_id   +   "% ' ");
                        if   (ds.Tables[0].Rows.Count   >   0)
                        {
                                for   (int   i   =   0;   i   <   ds.Tables[0].Rows.Count;   i++)
                                {
                                        CheckBox   cb   =   new   CheckBox();
                                        cb.ID   =   ds.Tables[0].Rows[i][ "inform_type "].ToString();
                                        cb.Text   =   ds.Tables[0].Rows[i][ "inform_desc "].ToString();
                                        PH_content.Controls.Add(cb);
                                        PH_content.Controls.Add(new   LiteralControl( "   "));
                                }
                        }
                }
  可是页面一刷新这些动态添加的控件就消失了,我也无法把控件的修改值,穿到后台去,请问哪位大侠有方法解决?

------解决方案--------------------
我看了我们公司代码中解决刷新后控件消失的方法是,没有ispostback的判断,每次都加载。