Recorrer WebControl
Publicado por nerea (1 intervención) el 20/04/2010 17:58:10
Hola buenas!!
Mi problema es que nos e como puedo recorrer los WebControls que una página .aspx pueda tener.
He intentado utilizando Me.controls pero no me aparecen los controles que yo tengo definidos.
Por ejemplo, yo tengo definidos estos controles, y quiero poder obtener todos los controles <asp> para poder cargar en ellos algunos valores.
<table class="tDatos">
<tr>
<td><asp:Label ID ="lblD_TORNEADO" CssClass="titulo3" runat="server" Text="Dimetro torneado"></asp:Label></td>
<td><asp:DropDownList ID="ctlD_TORNEADO" runat="server" CssClass="drpSeleccion"></asp:DropDownList></td>
</tr>
<tr>
<td><asp:Label ID ="lblH_MAX_TORNEADO" CssClass="titulo3" runat="server" Text="Altura mxima de torneado"></asp:Label></td>
<td><asp:DropDownList ID="ctlH_MAX_TORNEADO" runat="server" CssClass="drpSeleccion"></asp:DropDownList></td>
</tr>
<tr>
<td><asp:Label ID ="lblCURSO_TRAV" CssClass="titulo3" runat="server" Text="Curso Travesao"></asp:Label></td>
<td><asp:DropDownList ID="ctlCURSO_TRAV" CssClass="drpSeleccion" runat="server"></asp:DropDownList></td>
</tr>
</table>
Mi codigo:
ForEach miControl In Me.Controls
'Verificamos si el control es un TextBox
If (TypeOf (hijos) Is TextBox) Then
'CType(miControl, TextBox).Text = ""
End If
If (TypeOf (hijos) Is DropDownList) Then
'CType(miControl, DropDownList).SelectedIndex = 0
'cargarCombo(nombreVariable, master)
'SortDropDown(ctl.ID, master)
End If
If (TypeOf (hijos) Is RadioButtonList) Then
For i = 0 To CType(miControl, RadioButtonList).Items.Count - 1'CType(miControl, RadioButtonList).Items(i).Selected = False
Next
End If
If (TypeOf (hijos) Is CheckBoxList) Then
For i = 0 To CType(miControl, CheckBoxList).Items.Count - 1'CType(miControl, CheckBoxList).Items(i).Selected = False
Next
End If
If (TypeOf (hijos) Is DataGrid) Then
'CType(miControl, DataGrid).Controls.Clear()
End If
Next
Espero que me podais ayudar
Mi problema es que nos e como puedo recorrer los WebControls que una página .aspx pueda tener.
He intentado utilizando Me.controls pero no me aparecen los controles que yo tengo definidos.
Por ejemplo, yo tengo definidos estos controles, y quiero poder obtener todos los controles <asp> para poder cargar en ellos algunos valores.
<table class="tDatos">
<tr>
<td><asp:Label ID ="lblD_TORNEADO" CssClass="titulo3" runat="server" Text="Dimetro torneado"></asp:Label></td>
<td><asp:DropDownList ID="ctlD_TORNEADO" runat="server" CssClass="drpSeleccion"></asp:DropDownList></td>
</tr>
<tr>
<td><asp:Label ID ="lblH_MAX_TORNEADO" CssClass="titulo3" runat="server" Text="Altura mxima de torneado"></asp:Label></td>
<td><asp:DropDownList ID="ctlH_MAX_TORNEADO" runat="server" CssClass="drpSeleccion"></asp:DropDownList></td>
</tr>
<tr>
<td><asp:Label ID ="lblCURSO_TRAV" CssClass="titulo3" runat="server" Text="Curso Travesao"></asp:Label></td>
<td><asp:DropDownList ID="ctlCURSO_TRAV" CssClass="drpSeleccion" runat="server"></asp:DropDownList></td>
</tr>
</table>
Mi codigo:
ForEach miControl In Me.Controls
'Verificamos si el control es un TextBox
If (TypeOf (hijos) Is TextBox) Then
'CType(miControl, TextBox).Text = ""
End If
If (TypeOf (hijos) Is DropDownList) Then
'CType(miControl, DropDownList).SelectedIndex = 0
'cargarCombo(nombreVariable, master)
'SortDropDown(ctl.ID, master)
End If
If (TypeOf (hijos) Is RadioButtonList) Then
For i = 0 To CType(miControl, RadioButtonList).Items.Count - 1'CType(miControl, RadioButtonList).Items(i).Selected = False
Next
End If
If (TypeOf (hijos) Is CheckBoxList) Then
For i = 0 To CType(miControl, CheckBoxList).Items.Count - 1'CType(miControl, CheckBoxList).Items(i).Selected = False
Next
End If
If (TypeOf (hijos) Is DataGrid) Then
'CType(miControl, DataGrid).Controls.Clear()
End If
Next
Espero que me podais ayudar
Valora esta pregunta


0