繁体   English   中英

PerformClick on RadioButtonList ListItem

[英]PerformClick on RadioButtonList ListItem

我有一个带有Javascript onclick函数的RadioButtonList,当用户单击它时会触发它。 是否可以像单击单个RadioButton一样对整个单选按钮列表或单个ListItem进行performclick?

我有一个带有隐藏复选框的GridView,我用来了解用户是否对该行进行了修改:

    <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>

在gridview ondatabound上,我在单选按钮列表上分配了一个JavaScript,该JavaScript检查该隐藏的复选框,因此我知道我必须保存该行:

 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>

如果用户在某行的单选按钮列表上手动设置一个值,则效果很好。 发生问题是因为这是一个按钮,该按钮会自动将所有单选按钮列表设置为一个值,但是在这种情况下,不会触发javascript:

RadioButtonList rdDaPag = (RadioButtonList)riga.FindControl("rdDaPa");
rdDaPa.SelectedValue = "True";

因为没有人点击它。 我已经看到了: http : //msdn.microsoft.com/zh-cn/library/system.windows.forms.radiobutton.performclick%28v=vs.100%29.aspx ,我认为这是我需要的,但是是否可以在ListItem而不是RadioButton上使用?

好的,现在我正在用JavaScript进行所有操作,因此我可以直接选中隐藏的复选框:

    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;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM