Exemple #1
0
 /// <summary>
 /// Creates elements based on the fields in a database.
 /// Optionally, the elements are enclosed in a from with ID 'form_[formID]'.
 /// </summary>
 /// <param name="appID">The appID on which these controls are based.</param>
 /// <param name="cntlContainer">The container that contains these controls</param>
 /// <param name="dctDefaultOverride">A dictionary that maps the default value given in the database
 /// with the value to use as an override</param>
 /// <param name="uid">A unique identified to append to the control IDs of the generated controls.
 /// You will need this if you are calling this method several times to generate similar output one page.
 /// (One recommended value for thie Unique ID is the Database ID).</param>
 /// <param name="cntlDisplayStyle"></param>
 /// <param name="blElementsInLine">Set false to allow displaying all elements in line (no line breaks)</param>
 /// <param name="blRunAtServer">When TRUE, includes runat=server as a property of all controls</param>
 public static void GenerateControlsFromDatabase(int appID, System.Web.UI.Control cntlContainer,
                                                 Dictionary <string, string> dctDefaultOverride = null, string uid = "", int cntlDisplayStyle = -1,
                                                 Boolean blElementsInLine = false, Boolean blRunAtServer           = false)
 {
     try
     {
         if (dctDefaultOverride == null)
         {
             dctDefaultOverride = new Dictionary <string, string>();
         }
         SqlCommand          cmd   = new SqlCommand();
         clsDB               myDB  = new clsDB();
         ControlCollection   cntls = new ControlCollection(cntlContainer);
         List <SqlParameter> ps    = new List <SqlParameter>();
         ps.Add(new SqlParameter("@" + DBK.fkAPPID, appID));
         using (myDB.OpenConnection())
         {
             using (SqlDataReader dR = (SqlDataReader)myDB.ExecuteSP(DBK.SP.spGETWEBDISPLAYFIELDINFO,
                                                                     ps,
                                                                     clsDB.SPExMode.READER,
                                                                     ref cmd)
                    )
             {
                 if ((dR != null) && (dR.HasRows))
                 {
                     CustomCode x = new CustomCode();
                     x.ConstructInputControls(dR, cntlContainer, dctDefaultOverride, uid, cntlDisplayStyle,
                                              blElementsInLine, blRunAtServer);
                 }
             }
         }
     } catch (Exception ex)
     {
         cntlContainer.Controls.Add(renderLiteralControlError(ex, ""));
     }
 }