Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用c在复选框列表中选择单个项目_C#_Asp.net - Fatal编程技术网

C# 使用c在复选框列表中选择单个项目

C# 使用c在复选框列表中选择单个项目,c#,asp.net,C#,Asp.net,我使用asp.net页面中的复选框列表和数据库中的绑定数据。现在我想选择单个项目。假设我选择一个项目意味着清除旧的选择,只选择新的项目 请帮我做这件事。看起来RadioButton列表更合适,因为它只允许您选择单个元素 收音机按钮列表 看起来RadioButtonList更合适,因为它只允许您选择单个元素 收音机按钮列表 试试这个 前端 但不要做这一切,你应该考虑RadioButnListCube < P>试试这个 前端 但不要做这些事情,你应该考虑RadioButnListBuffic 。使

我使用asp.net页面中的复选框列表和数据库中的绑定数据。现在我想选择单个项目。假设我选择一个项目意味着清除旧的选择,只选择新的项目

请帮我做这件事。

看起来RadioButton列表更合适,因为它只允许您选择单个元素

收音机按钮列表

看起来RadioButtonList更合适,因为它只允许您选择单个元素

收音机按钮列表

试试这个

前端

<>但不要做这一切,你应该考虑RadioButnListCube

< P>试试这个

前端


<>但不要做这些事情,你应该考虑RadioButnListBuffic

。使用RadioButoLoad上的CabrBox列表有时是方便的,因为它允许用户取消选择,而不需要我发明一个工作。按照yogi的回答,我希望有一种方法可以轻松重用,而不必在每次使用时都将CheckBoxList的ClientID插入函数中。谢谢你的瑜伽模板

用法:

<asp:CheckBoxList ID="m_testControl" runat="server" data-toggle="radio" RepeatDirection="Horizontal">
    <asp:ListItem Value="CON">Concur</asp:ListItem>
    <asp:ListItem Value="CWI">Concur With Intent</asp:ListItem>
    <asp:ListItem Value="DNC">Do Not Concur</asp:ListItem>
</asp:CheckBoxList>

在RadioButtonList上使用复选框列表有时会很方便,因为它允许用户取消选择,而无需我发明一种变通方法。按照yogi的回答,我希望有一种方法可以轻松重用,而不必在每次使用时都将CheckBoxList的ClientID插入函数中。谢谢你的瑜伽模板

用法:

<asp:CheckBoxList ID="m_testControl" runat="server" data-toggle="radio" RepeatDirection="Horizontal">
    <asp:ListItem Value="CON">Concur</asp:ListItem>
    <asp:ListItem Value="CWI">Concur With Intent</asp:ListItem>
    <asp:ListItem Value="DNC">Do Not Concur</asp:ListItem>
</asp:CheckBoxList>
我正在保存所选项目的索引,当有更改时,我们将获得两个所选项目,因此在indexOfL的帮助下,我们将获得要保留的正确项目。 我不知道这种方法是否是最好的,因为这段代码在服务器端运行。。。。 希望对你有帮助

我正在保存所选项目的索引,当有更改时,我们将获得两个所选项目,因此在indexOfL的帮助下,我们将获得要保留的正确项目。 我不知道这种方法是否是最好的,因为这段代码在服务器端运行。。。。
希望能有帮助……

使用单选按钮会不会容易很多?使用单选按钮会不会容易很多?对不起,我在IE中做的,不在FF中工作,让我检查一下。对不起,我在IE中做的,不在FF中工作,让我检查一下。
<asp:CheckBoxList ID="m_testControl" runat="server" data-toggle="radio" RepeatDirection="Horizontal">
    <asp:ListItem Value="CON">Concur</asp:ListItem>
    <asp:ListItem Value="CWI">Concur With Intent</asp:ListItem>
    <asp:ListItem Value="DNC">Do Not Concur</asp:ListItem>
</asp:CheckBoxList>
$(document).ready(function ()
{
    // turn all CheckBoxLists labeled for 'radio' to be single-select
    $('[data-toggle=radio]').each(function ()
    {
        var clientId = $(this).attr('id');
        $(this).find('input').each(function ()
        {
            // set parent's id
            $(this).attr('data-parent', clientId);

            // add an onclick to each input
            $(this).click(function (e)
            {
                // ensure proper event
                if (!e) e = window.event;
                var sender = e.target || e.srcElement;
                if (sender.nodeName != 'INPUT') return;


                // toggle off siblings
                var id = $(this).attr('id');
                var parent = $(this).attr('data-parent');
                $('input[data-parent=' + parent + ']').not('#' + id).prop('checked', false);
            });
        });
    });
});
$('input[type=checkbox]').click(function () {
           var chks = document.getElementById('<%= chkBranchRoleTransaction.ClientID %>').getElementsByTagName('INPUT');
            for (i = 0; i < chks.length; i++) {
                    chks[i].checked = false;
            }
            $(this)[0].checked = true;
       });
        // or//
        $('input[type=checkbox]').click(function () {
             var chkBox = document.getElementById('<%= chkBranchRoleTransaction.ClientID %>');
            var chks = chkBox.getElementsByTagName('INPUT');
             for (i = 0; i < chks.length; i++) {
                 chks[i].checked = false;
             }
             $(this)[0].checked = true;
         });
    });[enter image description here][1]


  [1]: http://i.stack.imgur.com/zzaaz.jpg
var id = "";
$("#CblProduct").on('click', ':checkbox', function () {       
    if (id != "")
    {
        $(id).attr('checked', false);
        $(this).attr('checked', true);
    }
    if($("#CblProduct").length > 0)
    {
        id = this;
    }
});
static int indexOfL=0;// the index of initial selected item
    protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int i = 0;

        foreach (ListItem li in CheckBoxList1.Items)
        {    
            {
                if (i != indexOfL && li.Selected)
                {    
                    indexOfL=i;
                    CheckBoxList1.ClearSelection();
                    li.Selected = true;

                }
                i++;
            }
        }}