Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Tuesday, 23 December 2014

Get-Set All the Controls in the Form


DataTable dtCtrl = new DataTable();
            dtCtrl.Columns.Add("ctrlID");
            dtCtrl.Columns.Add("ctrlValue");

            ArrayList controlList = new ArrayList();
            GetControls(Page.Controls, controlList);
            foreach (string str in controlList)
            {
                if (this.Page.FindControl(str) != null)
                {
                    Control ctrl = Page.FindControl(str);
                    if (ctrl.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
                    {
                        TextBox txtBox = ctrl as TextBox;
                        if (txtBox.ReadOnly == true && txtBox.Visible == true)
                        {
                            DataRow dRow = dtCtrl.NewRow();
                            dRow["ctrlID"] = txtBox.UniqueID;
                            dRow["ctrlValue"] = Request[txtBox.UniqueID];
                            dtCtrl.Rows.Add(dRow);
                        }
                    }
                }
            }
            foreach (DataRow drow in dtCtrl.Rows)
            {
                (Page.FindControl(drow["ctrlID"].ToString()) as TextBox).Text = drow["ctrlValue"].ToString();
            }

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.