本文介绍了使用combogrid jquery-ASP.NET绑定数据以选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,当用户设置光标或键入选择时,网格将出现在选择控件下方以显示数据。然后用户将选择数据。现在,我正在使用combogrid jquery插件。我看过其他论坛的帖子,比如这个问题。但是我没有解决。



我尝试了什么:



在WebService1.asmx中,有一个返回列表数组的方法。

[WebMethod]

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]

public List< student> AutoArrayList(字符串查询)

{

//根据Query参数来做你的逻辑

List< student> lstStudents = new List< student>();

lstStudents.Add(新学生{StudentID = 1,StudentName =ABC});

lstStudents.Add(new学生{StudentID = 2,StudentName =DEF});

lstStudents.Add(新学生{StudentID = 3,StudentName =GHI});

lstStudents .Add(新学生{StudentID = 4,StudentName =JKL});

返回lstStudents;

}



公共班学生

{

public int StudentID {get;组; } $ / $
public string StudentName {get;组; }

}


默认.aspx中的


< link href =Scripts / easyui.css rel =stylesheettype =text / css/>

< link href =Scripts / icon.css =stylesheettype =text / css/>

< script src =Scripts /jquery.easyui.min.jstype =text / javascript>< / script>

< script src =Scripts / jquery.min.jstype =text / javascript>< / script>

< script src =Scripts / jquery.combogrid.jstype =text / javascript>< / script>



< script type =text / javascript>

$(function(){

var objval =param ;

var jsonData = [];

$ .ajax({

类型:POST,

async:false,

contentType:application / json; charset = utf-8,

url:'<%= ResolveUrl(WebService1.asmx / AutoArrayList )%>',

数据:{'查询':'+ objval +'},

dataType:json,

成功cess:function(data){

jsonData = data.d;

},

错误:函数(结果){

提醒(错误);

}



});



$('#drpSelectStudents')。combogrid({

panelWidth:290,

value:'006',

idField:'StudentID',

textField:'StudentName',

// url:'/ combogrid / GetStudentsInfo',

//来源:jsonData,

列:[[

{字段:'StudentName',标题:'StudentName',宽度:60}]]

});

//获取datagrid对象

var g = $('#drpSelectStudents')。combogrid('grid');

//将数据分配给datagrid

g.dat agrid('loadData',jsonData);

});



< / script>



in html正文

< select id =drpSelectStudentsname =Studentsstyle =width:290px;>< / select>





谁能告诉我错误在哪里以及如何解决这个问题?

感谢所有

In my application, when user set cursor or type on select, grid will be appeared beneath select control to show data. and then user will select data. Now, I am using combogrid jquery plugin. I saw a post from other forum like this issue. but I didn't solve.

What I have tried:

in WebService1.asmx, there is a method that return list array.
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<student> AutoArrayList(string Query)
{
//according to the Query parameter to do your logic
List<student> lstStudents = new List<student>();
lstStudents.Add(new Student { StudentID = 1, StudentName = "ABC" });
lstStudents.Add(new Student { StudentID = 2, StudentName = "DEF" });
lstStudents.Add(new Student { StudentID = 3, StudentName = "GHI" });
lstStudents.Add(new Student { StudentID = 4, StudentName = "JKL" });
return lstStudents;
}

public class Student
{
public int StudentID { get; set; }
public string StudentName { get; set; }
}

in Default.aspx,
<link href="Scripts/easyui.css" rel="stylesheet" type="text/css" />
<link href="Scripts/icon.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery.easyui.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.combogrid.js" type="text/javascript"></script>

<script type="text/javascript">
$(function () {
var objval = "param";
var jsonData = [];
$.ajax({
type: "POST",
async: false,
contentType: "application/json; charset=utf-8",
url: '<%=ResolveUrl("WebService1.asmx/AutoArrayList") %>',
data: "{'Query':'" + objval + "'}",
dataType: "json",
success: function (data) {
jsonData = data.d;
},
error: function (result) {
alert("Error");
}

});

$('#drpSelectStudents').combogrid({
panelWidth: 290,
value: '006',
idField: 'StudentID',
textField: 'StudentName',
//url: '/combogrid/GetStudentsInfo',
//source:jsonData,
columns: [[
{ field: 'StudentName', title: 'StudentName', width: 60}]]
});
// get the datagrid object
var g = $('#drpSelectStudents').combogrid('grid');
//assign the data to datagrid
g.datagrid('loadData', jsonData);
});

</script>

in body of html
<select id="drpSelectStudents" name="Students" style="width:290px;"></select>


can anyone tell me where the error is and how can I fix this?
Thanks all

推荐答案




这篇关于使用combogrid jquery-ASP.NET绑定数据以选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 22:45