使用webservice加载Jqwidgets数据表 [英] Jqwidgets datatable loading with webservice
本文介绍了使用webservice加载Jqwidgets数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hai朋友我正在使用jqwidgets插件来填充表格数据。
我的要求是通过组合框选择在桌面上显示数据
i am using asp.net
我的问题是如何将参数传递给函数GetCustomersfn(string cusID)
如果我使用参数减去函数,即GetCustomersfn()我得到了预期的结果。
请帮助..
下面给出的函数
[WebMethod]
[ScriptMethod(UseHttpGet = true ,ResponseFormat = ResponseFormat.Xml)]
public string GetCustomersfn( string cusID)
{
string query = SELECT * FROM Customers WHERE CustomerID LIKE @CustomerID;
string tablename = Customers跨度>;
SqlCommand cmd = new SqlCommand(query);
cmd.Parameters.AddWithValue( CustomerID, % + cusID.Substring( 0 , 1 )+ %);
DataSet data = GetData(cmd,tablename);
// 返回GetData(cmd,tablename).GetXml();
System.IO.StringWriter writer = new System.IO.StringWriter();
data.Tables [ 0 ]。WriteXml(writer,XmlWriteMode.WriteSchema, false );
return writer.ToString();
}
脚本文件如下:
< ; script type = text / javascript>
$( document )。ready( function (){
$(< span class =code-string>' #dlcustomers')。change( function (){
// var obj = {};
// obj.cusID = $ .trim($([id * = dlcustomers])。val());
// alert(obj.cusID);
var cid = $ .trim($( [id * = dlcustomers ])。val());
alert(cid);
source = {
datatype: xml,
datafields:[
{name:' CompanyName'},
{name:' ContactName'},
{name:' ContactTitle'},
{name:' City'},
{name :' Country'},
{name:' 地址'}
],
async: false ,
记录:' 客户,
url:' DataWebService.asmx / GetCustomersfn',
data:{CusID:< span class =code-string>' A'}
};
var dataAdapter = new $ .jqx.dataAdapter(source,
{contentType :' application / json; charset = utf-8'}
);
$( #dataTable)。jqxDataTable(
{
宽度: 850 ,
height: 400 ,
来源:dataAdapter,
pagerButtonsCount: 10 ,
pageable: true ,
columnsresize:< span class =code-keyword> true ,
altRows: true ,
filterable: true ,
sortable: true ,
filtermode:' advanced',
// pagerMode :'advanced',
// groups:['City'],
列:[
{text :' 公司名称',dataField:' CompanyName',width: 250 },
{text:' 联系人姓名',dataField:' ContactName',width: 150 },
{text:' 联系人标题',dataField:' ContactTitle',width: 180 },
{text:' 地址',dataField: ' 地址',宽度: 180 } ,
{text:' City',dataField:' 城市',宽度: 80 },
{text: ' Country',dataField:' < span class =code-string> Country',width: 100 }
]
});
});
});
< / script>
请帮助..提前感谢
解决方案
( document )。ready( function ( ){
(' #dlcustomers')。change( function (){
// var obj = {};
// obj.cusID =
.trim(
Hai friends i am using jqwidgets plugin to populate table data.
my requirement is to display data on table by the combobox selection
i am using asp.net
my problem is how to pass parameter to function "GetCustomersfn(string cusID)"
if i use parameter less function ie GetCustomersfn() i get the expected result.
please help..
Function given below
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
public string GetCustomersfn(string cusID)
{
string query = "SELECT * FROM Customers WHERE CustomerID LIKE @CustomerID";
string tablename = "Customers";
SqlCommand cmd = new SqlCommand(query);
cmd.Parameters.AddWithValue("CustomerID", "%" + cusID.Substring(0, 1) + "%");
DataSet data = GetData(cmd, tablename);
//return GetData(cmd, tablename).GetXml();
System.IO.StringWriter writer = new System.IO.StringWriter();
data.Tables[0].WriteXml(writer, XmlWriteMode.WriteSchema, false);
return writer.ToString();
}
script file is given below
<script type="text/javascript">
$(document).ready(function () {
$('#dlcustomers').change(function () {
// var obj = {};
// obj.cusID = $.trim($("[id*=dlcustomers]").val());
// alert(obj.cusID);
var cid = $.trim($("[id*=dlcustomers]").val());
alert(cid);
source = {
datatype: "xml",
datafields: [
{ name: 'CompanyName' },
{ name: 'ContactName' },
{ name: 'ContactTitle' },
{ name: 'City' },
{ name: 'Country' },
{ name: 'Address' }
],
async: false,
record: 'Customers',
url: 'DataWebService.asmx/GetCustomersfn',
data: { CusID: 'A'}
};
var dataAdapter = new $.jqx.dataAdapter(source,
{ contentType: 'application/json; charset=utf-8' }
);
$("#dataTable").jqxDataTable(
{
width: 850,
height: 400,
source: dataAdapter,
pagerButtonsCount: 10,
pageable: true,
columnsresize: true,
altRows: true,
filterable: true,
sortable: true,
filtermode: 'advanced',
// pagerMode: 'advanced',
// groups: ['City'],
columns: [
{ text: 'Company Name', dataField: 'CompanyName', width: 250 },
{ text: 'Contact Name', dataField: 'ContactName', width: 150 },
{ text: 'Contact Title', dataField: 'ContactTitle', width: 180 },
{ text: 'Address', dataField: 'Address', width: 180 },
{ text: 'City', dataField: 'City', width: 80 },
{ text: 'Country', dataField: 'Country', width: 100 }
]
});
});
});
</script>
please help.. thanks in advance
解决方案
(document).ready(function () {
('#dlcustomers').change(function () { // var obj = {}; // obj.cusID =
.trim(
这篇关于使用webservice加载Jqwidgets数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文