private void RecorrerYLimpiarControles(Control MyControl) { foreach (System.Web.UI.Control MyWebServerControl in MyControl.Controls) { if (MyWebServerControl.HasControls() == false) { switch (MyWebServerControl.GetType().Name.ToString()) { case "TextBox": System.Web.UI.WebControls.TextBox MyWebControlTextBox = (System.Web.UI.WebControls.TextBox)MyWebServerControl; MyWebControlTextBox.Text = ""; break; case "CheckBox": System.Web.UI.WebControls.CheckBox MyWebControlCheckbox = (System.Web.UI.WebControls.CheckBox)MyWebServerControl; MyWebControlCheckbox.Checked = false; break; case "ListBox": System.Web.UI.WebControls.ListBox MyWebControlListBox = (System.Web.UI.WebControls.ListBox)MyWebServerControl; MyWebControlListBox.SelectedIndex = -1; break; case "DropDownList": System.Web.UI.WebControls.DropDownList MyWebControlDropDownList = (System.Web.UI.WebControls.DropDownList)MyWebServerControl; MyWebControlDropDownList.SelectedIndex = -1; break; } } else { // en el control collection vienen Panels y web controls que // a su vez, contienen controls. RecorrerYLimpiarControles(MyWebServerControl); } } }
private void RecorrerControles1(ControlCollection MyControlCollection) { foreach (System.Web.UI.Control MyWebServerControl in MyControlCollection) { string typeOfControl = MyWebServerControl.GetType().Name.ToString(); if (!MyWebServerControl.HasControls() || MyWebServerControl.GetType().Name.ToString() == "CheckBoxList") { string controlName = MyWebServerControl.GetType().Name.ToString(); switch (controlName) { case "TextBox": System.Web.UI.WebControls.TextBox MyWebControlTextBox = (System.Web.UI.WebControls.TextBox)MyWebServerControl; if ((MyWebControlTextBox.Text != "")) { _ControlValues_String.Append((MyWebControlTextBox.ID.ToString() + ("=" + (MyWebControlTextBox.Text + "¦")))); } break; case "CheckBox": System.Web.UI.WebControls.CheckBox MyWebControlCheckbox = (System.Web.UI.WebControls.CheckBox)MyWebServerControl; if (MyWebControlCheckbox.Checked) { _ControlValues_String.Append((MyWebControlCheckbox.ID.ToString() + ("=" + (1 + "¦")))); } else { _ControlValues_String.Append((MyWebControlCheckbox.ID.ToString() + ("=" + (0 + "¦")))); } break; case "RadioButton": System.Web.UI.WebControls.RadioButton MyWebControlRadioButton = (System.Web.UI.WebControls.RadioButton)MyWebServerControl; if (MyWebControlRadioButton.Checked) { _ControlValues_String.Append((MyWebControlRadioButton.ID.ToString() + ("=" + (1 + "¦")))); } else { _ControlValues_String.Append((MyWebControlRadioButton.ID.ToString() + ("=" + (0 + "¦")))); } break; case "ListBox": System.Web.UI.WebControls.ListBox MyWebControlListBox = (System.Web.UI.WebControls.ListBox)MyWebServerControl; if ((MyWebControlListBox.SelectedIndex > -1)) { bool bFirstItem = true; foreach (int Index in MyWebControlListBox.GetSelectedIndices()) { if (bFirstItem) { _ControlValues_String.Append((MyWebControlListBox.ID.ToString() + ("=" + MyWebControlListBox.Items[Index].Text))); bFirstItem = false; } else { _ControlValues_String.Append((";" + MyWebControlListBox.Items[Index].Text)); bFirstItem = false; } } if (!bFirstItem) { _ControlValues_String.Append("¦"); } } break; case "CheckBoxList": System.Web.UI.WebControls.CheckBoxList MyWebControlCheckBoxList = (System.Web.UI.WebControls.CheckBoxList)MyWebServerControl; if ((MyWebControlCheckBoxList.SelectedIndex > -1)) { bool bFirstItem = true; for (int i = 0; i < MyWebControlCheckBoxList.Items.Count; i++) { if (MyWebControlCheckBoxList.Items[i].Selected) { if (bFirstItem) { _ControlValues_String.Append((MyWebControlCheckBoxList.ID.ToString() + ("=" + MyWebControlCheckBoxList.Items[i].Text))); bFirstItem = false; } else { _ControlValues_String.Append((";" + MyWebControlCheckBoxList.Items[i].Text)); bFirstItem = false; } } } if (!bFirstItem) { _ControlValues_String.Append("¦"); } } break; case "DropDownList": System.Web.UI.WebControls.DropDownList MyWebControlDropDownList = (System.Web.UI.WebControls.DropDownList)MyWebServerControl; // nuestra convenci�n es que un DropDownList cuyo valor // seleccionado es -1, 'no est� seleccionado'. La raz�n de // esto es que en Asp.Net un DropDownList SIEMPRE est� // seleccionado (!). if (((MyWebControlDropDownList.SelectedIndex > -1) && (((string)(MyWebControlDropDownList.SelectedItem.Value)) != "-1"))) { _ControlValues_String.Append((MyWebControlDropDownList.ID.ToString() + ("=" + (MyWebControlDropDownList.SelectedValue + "¦")))); } break; } } else { // en el control collection vienen Panels y web controls que // a su vez, contienen controls. RecorrerControles0(MyWebServerControl.Controls); } } }
public void ContruirFiltro1(ControlCollection MyControlCollection) { string sFiltroForma = ""; string sCriterioItemForma = ""; foreach (System.Web.UI.Control MyWebServerControl in MyControlCollection) { // leemos solo controles que empiezan con Sql ... if ((!(MyWebServerControl.ID == null) && (MyWebServerControl.ID.Substring(0, 3) == "Sql"))) { if ((gsIncluirExcluirItems != "")) { switch (gsIncluirExcluirItems) { case "I": // el nombre del item no existe en la lista de items; saltamos el item if (gsNombreItemsIncluirExcluir.IndexOf(MyWebServerControl.ID.ToString()) == -1) { continue; } break; case "E": // el nombre del item no existe en la lista de items; saltamos el item if (gsNombreItemsIncluirExcluir.IndexOf(MyWebServerControl.ID.ToString()) != -1) { continue; } break; } } sCriterioItemForma = ChekControl(MyWebServerControl); if ((sCriterioItemForma != "")) { if ((sFiltroForma == "")) { sFiltroForma = sCriterioItemForma; } else { sFiltroForma = (sFiltroForma + (" And " + sCriterioItemForma)); } } } else if (MyWebServerControl.HasControls()) { // en el control collection vienen Panels y web controls que // a su vez, contienen controls. ContruirFiltro0(MyWebServerControl.Controls); } } if ((sFiltroForma != "")) { // m_sMyCriterioSql es la variable que pasamos cuando se pide el resultado de la clase (propiedad CriterioSql) if ((m_sMyCriterioSql == "")) { m_sMyCriterioSql = sFiltroForma; } else { m_sMyCriterioSql = (m_sMyCriterioSql + (" And " + sFiltroForma)); } } }