I have a RadioButtonList with a javascript onclick function that is triggered when a user click on it. It's possible to have a performclick on the entire radiobuttonlist or on one single ListItem as is possible on a single RadioButton?
I've a GridView with an hidden checkbox that I use to know if user have modified something on that row:
<asp:TemplateField ShowHeader="false" HeaderStyle-BackColor="White">
<ItemStyle BorderColor="White" Width="5%" />
<ItemTemplate>
<asp:CheckBox runat="server" Style="display: none" Text="" ID="chkDaPa" Checked="false" />
</ItemTemplate>
</asp:TemplateField>
on the gridview ondatabound I assign on a radiobuttonlist a javascript that check that hidden checkbox, so I know that I have to save that row:
rdDaPa.Attributes.Add("onclick", "$('#" + chkDaPa.ClientID + "').attr('checked', true);");
<asp:TemplateField>
<ItemStyle HorizontalAlign="Center" Width="10%" Wrap="false" />
<ItemTemplate>
<asp:RadioButtonList RepeatLayout="Flow" ID="rdDaPa" runat="server" RepeatDirection="Horizontal" SelectedValue='<%#Eval("DaPa")%>'>
<asp:ListItem Text="SI" Value="True"></asp:ListItem>
<asp:ListItem Text="NO" Value="False"></asp:ListItem>
<asp:ListItem Value="" Text="" style="display: none" />
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
And it's working fine if the user manually set a value on the radiobuttonlist on some row. The problem occur because that's a button that automatically set all the radiobuttonlist on a value, but in that case the javascript isn't triggered:
RadioButtonList rdDaPag = (RadioButtonList)riga.FindControl("rdDaPa");
rdDaPa.SelectedValue = "True";
Because no one has clicked on it. I've seen this: http://msdn.microsoft.com/en-us/library/system.windows.forms.radiobutton.performclick%28v=vs.100%29.aspx and I think that's what I need, but it's possible to use on a ListItem instead of a RadioButton?
Ok, now I'm doing all by javascript, so I can directly check the hidden checkbox:
function accettaTutte() {
$("#<%=gdDettaglio.ClientID%> tr:has(td)").each(function () {
var items = $(this).find("[id$='rdDaPa'] input:radio'");
for (var i = 0; i < items.length; i++) {
if (items[i].value == 'True') {
if (!(items[i].checked)) {
items[i].checked = true;
$(this).find("[id$='chkDaPa']").attr("checked", "checked");
}
break;
}
}
});
return false;
}