Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Oi
Tenho o seguinte problema
Tenho um repeater que vai buscar dados à BD, para cada linha de dados quero colocar um radioButton para selecção
O problema é que quero que só se possa escolher um radioButton de cada linha.
qualquer coisa do género
linha 1 - dados1 (RadioButton) - dados2 (RadioButton) - dados3 (RadioButton)
linha 2 - dados1 (Radio) - dados2 (Radio)
linha 3 - dados1 (RadioButton) - dados2 (RadioButton) - dados3 (RadioButton) - dados4 (RadioButton) - dados5 (RadioButton)
Na minha aplicação ele só deixa escolher 1 radioButton na página toda e o pretendido era escolher um por linha.
O meu código
Função javascript
function MakeExclusiveCheck(rbcntrl)
{
var allrbcntrls = document.getElementsByTagName("input");
for(var loop = 0; loop < allrbcntrls.length; loop++)
{
if(allrbcntrls[loop].type == 'radio' && allrbcntrls[loop].id.indexOf("RepeaterTurno") >= 0)
allrbcntrls[loop].checked = false;
}
document.getElementById(rbcntrl).checked = true;
}
--------------------
<asp:Repeater ID="RepeaterUc" runat="server" >
<ItemTemplate>
<asp:Label ID="LblUc" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"nome") %>'></asp:Label> -
<asp:HiddenField ID="hiddenIdUc" runat="server" Value='<%# DataBinder.Eval(Container.DataItem,"uc") %>' />
<asp:Repeater ID="RepeaterTurno" runat="server" onitemdatabound="RepeaterTurno_ItemDataBound">
<ItemTemplate>
<asp:Label ID="LblTurno" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"AbrvTipoHora") %>'></asp:Label>
<asp:Label ID="LblNumero" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"numero") %>'></asp:Label>
<asp:RadioButton ID="rbClick" runat="server" GroupName='<%#Eval("uc") %>' />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
</asp:Repeater>
---------------------------------
back code
protected void Page_Load(object sender, EventArgs e)
{
ViewAlunoUCsBLL alunosAPI = new ViewAlunoUCsBLL();
RepeaterUc.DataSource = alunosAPI.GetAlunoUCsByAlunoId(188);
RepeaterUc.DataBind();
foreach (RepeaterItem repeaterItem in RepeaterUc.Items)
{
int ucId = Convert.ToInt32(((HiddenField)repeaterItem.FindControl("hiddenIdUc")).Value);
ViewTurnosBLL turnosAPI = new ViewTurnosBLL();
((Repeater)(repeaterItem.FindControl("RepeaterTurno"))).DataSource = turnosAPI.GetTurnosByUcId(ucId);
((Repeater)(repeaterItem.FindControl("RepeaterTurno"))).DataBind();
}
}
protected void RepeaterTurno_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
{
RadioButton rbClick = (RadioButton)e.Item.FindControl("rbClick");
rbClick.Attributes.Add("onclick", "java script:return MakeExclusiveCheck('" + rbClick.ClientID + "')");
}
}
Agradeço qualquer ajuda
Obrigado
Carregando comentários...