1:继承了母板页后。遍历内容页中的控件

  a:内容页继承了母板页。可以这样遍历内容页中的控件

    

            foreach (Control cp in Page.Controls)
            {
                foreach (System.Web.UI.Control ct in cp.Controls)
                {
                    if (ct is HtmlForm)
                    {
                        foreach (Control con in ct.Controls)
                        {
                            foreach (Control c in con.Controls)
                            {
                                //string typeName = c.GetType().Name; //获取 控件类型

                                if (c is TextBox)
                                {
                                    string tempId = (c as TextBox).ID;
                                    //排除配置文件中的三个文本框
                                    if (tempId == "tableName" || tempId == "QuerySift" || tempId == "QueryType")
                                        continue;
                                    if (!string.IsNullOrEmpty((c as TextBox).Text))
                                    {
                                        if ((c as TextBox).ID == "add")
                                        {
                                            string value = (c as TextBox).Text;
                                            search.Add("add", value.Trim());
                                            searchAdd.Append(string.Format("(add1 like {0} or add2 like {1} or add3 like {2})", "@add1", "@add2", "@add3"));

                                        }
                                        //如果手机/电话输入框有值
                                        else if ((c as TextBox).ID == "phonetell")
                                        {
                                            string value = (c as TextBox).Text;
                                            search.Add("phone", value.Trim());
                                            searchPhone.Append(string.Format("(tel1 like {0} or mphone like {1})", "@tel1", "@mphone"));
                                        }
                                        else
                                            //筛选信息以 K-V的方式保存
                                            search.Add((c as TextBox).ID.Trim(), (c as TextBox).Text.Trim());
                                    }
                                }
                                else if (c is DropDownList)
                                {
                                    if ((c as DropDownList).SelectedValue != "请选择")
                                        search.Add((c as DropDownList).ID.Trim(), (c as DropDownList).SelectedValue.Trim());
                                }
                                else if (c is RadioButton)
                                {
                                    // RadioButton d = new RadioButton();

                                }
                                else if (c is RadioButtonList)
                                {
                                    //多选就拼接string.Format("");
                                }

                            }
                        }
                    }
                }
            }
View Code

相关文章: