Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.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# 使用ASP.NET和AJAX从复选框列表填充文本框_C#_Asp.net_Jquery_Ajax - Fatal编程技术网

C# 使用ASP.NET和AJAX从复选框列表填充文本框

C# 使用ASP.NET和AJAX从复选框列表填充文本框,c#,asp.net,jquery,ajax,C#,Asp.net,Jquery,Ajax,我的页面上有一个文本框控件和一个复选框列表控件 我首先用代码隐藏中的employee对象列表填充复选框列表。员工有一个id和一个名字。这两者都显示在复选框列表中,如下所示: 吉姆(1) 亚历克斯(2) 加里(3) 当用户选中其中一个框时,需要在文本框中填充员工的姓名。因此,如果选择Jim,文本框值为“Jim”。它还需要支持多个值,因此如果选择Jim和Gary,文本框值为“Jim,Gary” 此外,如果用户在文本框中输入有效值,则应选中正确的员工。这需要支持名称和id。因此,如果我在文本框中输

我的页面上有一个文本框控件和一个复选框列表控件

我首先用代码隐藏中的employee对象列表填充复选框列表。员工有一个id和一个名字。这两者都显示在复选框列表中,如下所示:

  • 吉姆(1)
  • 亚历克斯(2)
  • 加里(3)
当用户选中其中一个框时,需要在文本框中填充员工的姓名。因此,如果选择Jim,文本框值为“Jim”。它还需要支持多个值,因此如果选择Jim和Gary,文本框值为“Jim,Gary”

此外,如果用户在文本框中输入有效值,则应选中正确的员工。这需要支持名称和id。因此,如果我在文本框中输入“1,Alex”,然后在文本框外单击,Jim和Alex应该被选中


我正在使用ASP.NET,我需要使用AJAX来实现这一点,但我没有使用jQuery和AJAX的经验。有人能给我举一个简单的例子说明如何做到这一点吗?

以下是我共同经历的一些事情,可能会帮助您开始。它没有经过测试,也不完整,但我现在没有时间去做,所以我想这可能会有所帮助。肯定需要做更多的检查和削减,我没有给你们实施

$(function() {
    // gets all checkbox items by a common class you will put on all of them
    $('.checkboxlistclass').click(function(e) {
        var txt = $(this).text();
        var employeeName = txt; // change this to parse out the name part and remove the id

        var currentTxtVal = $('#textboxid').val();
        var newVal = currentTxtVal + ',' + employeeName; // check if you need the comma or not

        $('#textboxid').val(newVal);
    });

    // textboxid is the id of the textbox
    $('#textboxid').change(function(e) {
        var textboxVal = $(this).val();

        // split on the comma and get an array of items
        // this is dummy data
        var items = [];
        items.push('Jim');
        items.push(2);

        // go through all the items and check if it's a number or not
        // if it's a number do a selection based on the id in parenthesis
        // if not then check first part for name match
        for (var i=0; i < items.length; i++) {
            if (isNaN(parseInt(items[i])) {
                $(".checkboxlistclass:contains('" + items[i] + " ('").attr('checked', true);
            }
            else {
                $(".checkboxlistclass:contains(' (" + items[i] + ")'").attr('checked', true);
            }
        }
    });
});
$(函数(){
//按您将放置在所有复选框项上的公共类获取所有复选框项
$('.checkboxlistclass')。单击(函数(e){
var txt=$(this.text();
var employeeName=txt;//将其更改为解析出名称部分并删除id
var currentTxtVal=$('#textboxid').val();
var newVal=currentTxtVal+','+employeeName;//检查是否需要逗号
$('#textboxid').val(newVal);
});
//textboxid是文本框的id
$('#textboxid').change(函数(e){
var textboxVal=$(this.val();
//按逗号拆分并获取项目数组
//这是虚拟数据
var项目=[];
项目。推送(“Jim”);
项目。推送(2);
//检查所有的项目,检查它是否是一个数字
//如果是数字,请根据括号中的id进行选择
//如果没有,则检查第一部分的名称是否匹配
对于(变量i=0;i