Foros del Web » Programando para Internet » ASPX (.net) »

Problema con RadioButtonList enlazado a datos

Estas en el tema de Problema con RadioButtonList enlazado a datos en el foro de ASPX (.net) en Foros del Web. Estoy trabajando con un control radioButtonList enlazado a datos y tengo problema recuperando cual elemento fue seleccionado. autoPostBack = true elemento 1 valor 0 elemento ...
  #1 (permalink)  
Antiguo 04/02/2006, 17:01
 
Fecha de Ingreso: febrero-2006
Mensajes: 2
Antigüedad: 18 años, 3 meses
Puntos: 0
Problema con RadioButtonList enlazado a datos

Estoy trabajando con un control radioButtonList enlazado a datos y tengo problema recuperando cual elemento fue seleccionado.

autoPostBack = true

elemento 1 valor 0
elemento 2 valor 0
elemento 3 valor 1
elemento 4 valor 0


selectedItem --> indica el elemento seleccionado (correcto) si selecciono el
primero o el de valor diferente (elemento 1 ó elemento 3)
Si selecciono otro elemento diferente a 1 ó 3 cuando se recarga la página se
marca como seleccionado el primer elemento

autoPostBack = false

selectedItem --> siempre es una referencia nula

Tienen alguna idea de que puedo estar haciendo mal?
pd: todo en onPageLoad está entre if not page.isPostBack end if

Gracias anticipadas por sus respuestas
Saludos a todos

Última edición por Bluewake; 04/02/2006 a las 18:08
  #2 (permalink)  
Antiguo 04/02/2006, 17:41
 
Fecha de Ingreso: agosto-2005
Ubicación: Argentina, Capital Federal
Mensajes: 435
Antigüedad: 18 años, 8 meses
Puntos: 2
Hola, bueno supongo que deberías adjuntarnos el código para poder buscar el error. Por mi parte te dejo un ejemplo en C# (lo podrías adaptar) que realiza esto mismo que pides con AutoPostBack=true, a lo mejor te sirve para encontrar tu error.

Código:
<script runat="server">
void Page_Load(Object Src, EventArgs E)
{
	if(!Page.IsPostBack)
	{

		/* Aca iria la conexion a la base de datos y el llenado de la variable dSet con el contenido de un DataSet o un DataReader */

		combo.DataSource=dSet;
		combo.DataBind();
	}
}

void cambio(Object Src, EventArgs E)
{
	Response.Write("Seleccionaste: "+combo.SelectedItem.Text);
}
</script>

<html>
<body>
<form runat="server">

<asp:RadioButtonList runat="server" ID="combo" AutoPostBack="true" DataTextField="nombre"
OnSelectedIndexChanged="cambio" RepeatColumns="2" RepeatDirection="Horizontal" />

</form>
</body>
</html>
Espero te sea útil. Saludos!
__________________
R4DS en español | R4DS en inglés
  #3 (permalink)  
Antiguo 04/02/2006, 18:07
 
Fecha de Ingreso: febrero-2006
Mensajes: 2
Antigüedad: 18 años, 3 meses
Puntos: 0
200.25.188.241/SAED/WebForm2.aspx

Public Class WebForm2
Inherits System.Web.UI.Page
Protected WithEvents RadioButtonList1 As System.Web.UI.WebControls.RadioButtonList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents RadioButtonList2 As System.Web.UI.WebControls.RadioButtonList
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Dim learnEst As New PryLearn.ClsEstudiante()

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load

'Introducir aquí el código de usuario para inicializar la página
If Page.IsPostBack = False Then
'Enlace a datos del rbl1
Dim ds As New System.Data.DataSet()
ds = learnEst.respuestas(1)
Me.RadioButtonList1.DataSource = ds
Me.RadioButtonList1.DataBind()
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click

'Prueba identificacion de elemento seleccionado
Me.Label1.Text = Me.RadioButtonList1.SelectedItem.Text
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click

'Prueba identificacion de elemento seleccionado
Me.Label2.Text = Me.RadioButtonList2.SelectedItem.Text
End Sub

Private Sub RadioButtonList2_SelectedIndexChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles RadioButtonList2.SelectedIndexChanged

'Prueba identificacion de elemento seleccionado
Me.Label2.Text = Me.RadioButtonList2.SelectedItem.Value
End Sub

Private Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged

'Prueba identificacion de elemento seleccionado
Me.Label1.Text = Me.RadioButtonList1.SelectedItem.Value
End Sub

End Class

------------------------------------------------------------------------------------------

<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:RadioButtonList id="RadioButtonList1" style="Z-INDEX: 101; LEFT: 320px; POSITION: absolute; TOP: 224px" runat="server" DataValueField="valresp" DataTextField="resp" AutoPostBack="True"></asp:RadioButtonList>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 344px; POSITION: absolute; TOP: 136px" runat="server">Label</asp:Label>
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 336px; POSITION: absolute; TOP: 168px" runat="server" Text="Button"></asp:Button>
<asp:RadioButtonList id="RadioButtonList2" style="Z-INDEX: 104; LEFT: 80px; POSITION: absolute; TOP: 224px" runat="server" AutoPostBack="True">
<asp:ListItem Value="valoruva">uva</asp:ListItem>
<asp:ListItem Value="valormanzana">manzana</asp:ListItem>
<asp:ListItem Value="valorpera">pera</asp:ListItem>
<asp:ListItem Value="valorciruela">ciruela</asp:ListItem>
</asp:RadioButtonList>
<asp:Button id="Button2" style="Z-INDEX: 105; LEFT: 104px; POSITION: absolute; TOP: 176px" runat="server" Text="Button"></asp:Button>
<asp:Label id="Label2" style="Z-INDEX: 106; LEFT: 112px; POSITION: absolute; TOP: 136px" runat="server">Label</asp:Label>
<asp:Label id="Label3" style="Z-INDEX: 107; LEFT: 88px; POSITION: absolute; TOP: 96px" runat="server">ESTATICO</asp:Label>
<asp:Label id="Label4" style="Z-INDEX: 108; LEFT: 296px; POSITION: absolute; TOP: 96px" runat="server">DINAMICO (enlazado a datos)</asp:Label>
</form>
</body>

muchas gracias zaqpz por tu código, lo estoy revisando
saludos, Bluewake

Última edición por Bluewake; 04/02/2006 a las 18:16
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:13.