正如我在 Internet 上发现的那样,当我们在中继器中添加一个 RadioButton 以仅选择一个时,MS 会出现错误。
但我在这里找到了解决我问题的代码。 ( only one radiobutton selection in repeater )
$(function () {
$('[name$="$YourGroupName"]').attr("name", $('[name$="$YourGroupName"]').attr("name"));
$('[name$="$YourGroupName"]').click(function () {
//set name for all to name of clicked
$('[name$="$YourGroupName"]').attr("name", $(this).attr("name"));
});
});
但它只在单选按钮未设置为自动回传时有效。但是当我选择一个单选按钮和对数据库的响应时,我需要进行回发。但是....每当我点击带有回发的单选按钮时,总是选择列表中的第一个并且 ItemDataBound 它不起作用,因为它正在重命名所有具有相同名称的单选按钮的 jquery 函数。
建议?
最佳答案
尝试在页面末尾的中继器之后添加此脚本,而不是您正在使用的脚本:
<script>
var radios = $("input:radio");
radios.click(function () {
radios.removeAttr('checked');
$(this).prop("checked", true);
//$(this).attr('checked', 'checked'); // jQuery < 1.6
return true;
});
</script>
这将允许您的单选按钮的 AutoPostBack 再次工作。
关于c# - 如何在带有回发的转发器中只选择一个单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20338755/