【问题标题】:PerformClick on RadioButtonList ListItem执行单击 RadioButtonList ListItem
【发布时间】:2014-10-23 16:46:58
【问题描述】:

我有一个带有 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上,我在radiobuttonlist上分配了一个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/en-us/library/system.windows.forms.radiobutton.performclick%28v=vs.100%29.aspx,我认为这就是我需要的,但是可以在 ListItem 上使用而不是 RadioButton?

【问题讨论】:

  • 是的,一切皆有可能。只需粘贴您尝试过的代码

标签: javascript c# asp.net onclick radiobuttonlist


【解决方案1】:

好的,现在我都是用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;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    • 2023-03-11
    • 1970-01-01
    相关资源
    最近更新 更多