本文介绍了如何在Jqxgrid中传递参数以进行绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
i有asp.net网站,
我用jqxgrid绑定来自html表的数据,
我在这个表中有一个添加按钮,我正在调用这个ADD2Grid()。
代码:
< script type =text / javascript>
函数ADD2Grid(){
//使用ajax GET请求获取源数据
var tt = $('#ddltitle:selected')。text()+| +
$(#<%= txtfn.ClientID%>)。val()+| +
$(#<%= txtmn.ClientID%>)。val()+| +
$(#<%= txtln.ClientID%>)。val();
// alert(tt);
source = {
datatype:xml,
datafields:[
{name:'Title',type:'string'},
{name:' First Name',type:'string'},
{name:'Middle Name',type:'string'},
{name:'Last Name',type:'string'}
],
async:false,
记录:'表',
url:'Default.aspx / GetCustomers',
数据:'{data1:'+ tt + '}',//错误
成功:alert(data.d)
};
var dataAdapter = new $ .jqx.dataAdapter(source,
{contentType:'application / json; charset = utf-8'}
);
$(#jqxgrid)。jqxGrid({
source:dataAdapter,
theme:'classic',
columns:[
{text:'Title' ,dataField:'Title',width:50},
{text:'First Name',dataField:'First Name',width:250},
{text:'Middle Name',dataField: '中间名',宽度:250},
{text:'姓氏',dataField:'姓氏',宽度:250}
]
});
};
< / script>
Default.aspx
protected static DataSet GetData(string data)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
if(dt == null)
{
dt.Columns.Add(Title,typeof(string));
dt.Columns.Add(First Name,typeof(string));
dt.Columns.Add(Middle Name,typeof(string));
dt.Columns.Add(姓氏,typeof(字符串));
}
其他
{
dt = HttpContext.Current.Session [MyTable] as DataTable;
}
string [] split = data.Split('|');
DataRow dr = dt.NewRow();
dr [Title] = split [0];
dr [First Name] = split [1];
dr [Middle Name] = split [2];
dr [姓氏] =分裂[3];
dt.Rows.Add(dr);
HttpContext.Current.Session [MyTable] = dt;
ds.Tables.Add(dt);
返回ds;
}
[WebMethod]
[ScriptMethod(UseHttpGet = true,ResponseFormat = ResponseFormat.Xml)]
public static string GetCustomers(string data1)
{
//填充DataSet。
DataSet data = GetData(data1);
//将Customers表作为XML返回。
StringWriter writer = new StringWriter();
data.Tables [0] .WriteXml(writer,XmlWriteMode.WriteSchema,false);
返回writer.ToString();
}
任何人都可以帮助我。
谢谢
解决方案
Hi guys,
i have asp.net website,
where i'm using jqxgrid to bind data from a html table,
I have one add button in this table and i'm calling this ADD2Grid().
Code:
<script type="text/javascript"> function ADD2Grid() { //Getting the source data with ajax GET request var tt = $('#ddltitle :selected').text() + "|" + $("#<%=txtfn.ClientID %>").val() + "|" + $("#<%=txtmn.ClientID %>").val() + "|" + $("#<%=txtln.ClientID %>").val(); //alert(tt); source = { datatype: "xml", datafields: [ { name: 'Title', type: 'string' }, { name: 'First Name', type: 'string' }, { name: 'Middle Name', type: 'string' }, { name: 'Last Name', type: 'string' } ], async: false, record: 'Table', url: 'Default.aspx/GetCustomers', data: '{ data1:' + tt + '}',//Error success: alert(data.d) }; var dataAdapter = new $.jqx.dataAdapter(source, { contentType: 'application/json; charset=utf-8'} ); $("#jqxgrid").jqxGrid({ source: dataAdapter, theme: 'classic', columns: [ { text: 'Title', dataField: 'Title', width: 50 }, { text: 'First Name', dataField: 'First Name', width: 250 }, { text: 'Middle Name', dataField: 'Middle Name', width: 250 }, { text: 'Last Name', dataField: 'Last Name', width: 250 } ] }); }; </script>
Default.aspx
protected static DataSet GetData(string data) { DataSet ds = new DataSet(); DataTable dt = new DataTable(); if (dt == null) { dt.Columns.Add("Title", typeof(string)); dt.Columns.Add("First Name", typeof(string)); dt.Columns.Add("Middle Name", typeof(string)); dt.Columns.Add("Last Name", typeof(string)); } else { dt = HttpContext.Current.Session["MyTable"] as DataTable; } string[] split = data.Split('|'); DataRow dr = dt.NewRow(); dr["Title"] = split[0]; dr["First Name"] = split[1]; dr["Middle Name"] = split[2]; dr["Last Name"] = split[3]; dt.Rows.Add(dr); HttpContext.Current.Session["MyTable"] = dt; ds.Tables.Add(dt); return ds; } [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)] public static string GetCustomers(string data1) { // Populate the DataSet. DataSet data = GetData(data1); // return the Customers table as XML. StringWriter writer = new StringWriter(); data.Tables[0].WriteXml(writer, XmlWriteMode.WriteSchema, false); return writer.ToString(); }
Can any one please help me.
Thanks
解决方案
这篇关于如何在Jqxgrid中传递参数以进行绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!