jQuery UI Widgets › Forums › Plugins › Data Adapter › Web Services
Tagged: angular dataadapter, bootstrap dataadapter, dataadapter, javascript dataadapter, jquery dataadapter, jqwidgets dataadapter, Web Services
This topic contains 6 replies, has 2 voices, and was last updated by Amar Kansara 8 years, 3 months ago.
-
AuthorWeb Services Posts
-
Dear Admin,
I am facing a problem with collecting data using web service. My web service is suppose to return the data in XML format. The web service is hosted on localhost (IIS) and working perfectly fine when being accessed directly from browser, but it failing to present data on widgets controls bound to data adaptor.
Please help
Amar Kansara
Hello Amar Kansara,
We have different examples with binding to XML:
http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxdataadapter/bindingtoxml.htm?light
http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/bindingtoxml.htm?light
http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxcombobox/bindingtoxml.htm?light
(this examples could be useful)
Please provide us simple example with that you try to do.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comDear Hristo,
Thank you for the reply. But this is not what I am looking for. This examples I already have consumed in several pages in my test projects. I even have successfully tried several projects by collecting data in xml format into dataAdapter and bind it with several widgets using webmethods.
Now, I want to do the same by writing the webmethods in a webservice.
Following is my WebService Code;
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data;
using System.Web.Script.Services;
using System.Configuration;/// <summary>
/// Summary description for GenDataService
/// </summary>
[WebService(Namespace = “http://pppl.com/webservices/”)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class GenDataService : System.Web.Services.WebService {public GenDataService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
public string GetUsers()
{
string Sql = “Select UserName, UserID From NIFUsers”;
SqlCommand cmd = new SqlCommand(Sql);DataSet ds = GetData(cmd);
System.IO.StringWriter writer = new System.IO.StringWriter();
ds.Tables[0].WriteXml(writer, XmlWriteMode.WriteSchema, false);
return writer.ToString();
}[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
public string GetMI()
{
string Sql = “SELECT MenuID, Posturl FROM NIFMenuSystem”;
SqlCommand cmd = new SqlCommand(Sql);
// Populate the DataSet.
DataSet ds = GetData(cmd);
// return the Customers table as XML.
System.IO.StringWriter writer = new System.IO.StringWriter();
ds.Tables[0].WriteXml(writer, XmlWriteMode.WriteSchema, false);
return writer.ToString();
}[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
public string getMenu()
{
string Sql;
Sql = “SELECT MenuID As id, ParentID, MenuText, SubmenuWidth, Posturl From NIFMenuSystem Where MenuID <> ‘-1’ Order By MenuID”;
SqlCommand cmd = new SqlCommand(Sql);
// Populate the DataSet.
DataSet data = GetData(cmd);
// return the Customers table as XML.
System.IO.StringWriter writer = new System.IO.StringWriter();
data.Tables[0].WriteXml(writer, XmlWriteMode.WriteSchema, false);
return writer.ToString();
}private static DataSet GetData(SqlCommand cmd)
{
string strConnString = ConfigurationManager.ConnectionStrings[“PPPL”].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
try
{
sda.Fill(ds);
}
catch (Exception ex)
{
RecordError(“GetData”, ex.Message);
}
return ds;
}
}
}
}private static void RecordError(string ErrLoc, string ErrMsg)
{
string Sql;
string conStr = ConfigurationManager.ConnectionStrings[“PPPL”].ConnectionString;
using (SqlConnection con = new SqlConnection(conStr))
{
Sql = “INSERT INTO ErrorLog VALUES(‘” + ErrLoc + “‘, ‘” + ErrMsg + “‘)”;
using (SqlCommand InsCmd = new SqlCommand(Sql))
{
InsCmd.CommandType = CommandType.Text;
InsCmd.Connection = con;
con.Open();
InsCmd.ExecuteNonQuery();
}
con.Close();
}
}
}This webservice is hosted successfully on localhost (IIS) and working as expected.
Following is my script.
<script type=”text/javascript”>
$(document).ready(function() {
// prepare the data
var SrcMI =
{
datatype: “xml”,
datafields: [
{ name: ‘MenuID’ },
{ name: ‘Posturl’ }
],
async: false,
record: ‘Table’,
url: ‘http://localhost/PPPLWebService/GenDataService.asmx/GetMI’
};
var mDA = new $.jqx.dataAdapter(SrcMI, { contentType: ‘application/json; charset=utf-8’ });
mDA.dataBind();$(“#jqxDropDown”).jqxDropDownList({
selectedIndex: 0, source: mDA, displayMember: “Posturl”, valueMember: “MenuID”, width: 100, height: 25
});var sourceM =
{
datatype: “xml”,
datafields: [
{ name: ‘id’ },
{ name: ‘ParentID’ },
{ name: ‘MenuText’ },
{ name: ‘SubmenuWidth’ },
{ name: ‘Posturl’ }
],
id: ‘id’,
async: false,
record: ‘Table’,
url: ‘http://localhost/PPPLWebService/GenDataService.asmx/getMenu’
};// create MenuDA data adapter.
var MenuDA = new $.jqx.dataAdapter(sourceM, { contentType: ‘application/json; charset=utf-8’ });
MenuDA.dataBind();var records = MenuDA.getRecordsHierarchy(‘id’, ‘ParentID’, ‘items’, [{ name: ‘MenuText’, map: ‘label’}]);
$(‘#jqxMenu’).jqxMenu({ source: records, height: 30, width: ‘650px’ });
$(‘#jqxMenu’).jqxMenu({clickToOpen: true});
$(‘#jqxMenu’).jqxMenu({autoOpen: true});
$(“#jqxMenu”).on(‘itemclick’, function(event)
{
var item = $(“#jqxDropDown”).jqxDropDownList(‘getItemByValue’, event.args.id);
//alert(item.label);
if (item.label != ”)
{
window.open(‘<%= ResolveUrl(“‘+ item.label + ‘”) %>’, ‘_top’);
}
});
});
</script>My Database is in SQLServer 2005. And it was working perfectly good with earlier project.
Hello Amar Kansara,
Thank you for your understanding.
Please, take a look those articles:
http://www.jqwidgets.com/jquery-widgets-documentation/documentation/asp.net-integration/asp.net-web-service-grid.htm?search=
http://www.jqwidgets.com/jquery-widgets-documentation/documentation/asp.net-integration/asp.net-web-service-chart.htm?search=Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comHello Hristo,
I tried that too with no luck.
I even tried to convert the webservice to output data in JSON format, but still no result.
ThanksHello Amar Kansara,
Excuse me for the delay.
I would like to ask you is there any error message in the console?
Also could you try to setloadError
callback of the DataAdapter to check for some errors messages.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comDear Hristo,
Sorry for the late reply.. So far I was working with earlier version of jqxWidgets. Just today I have downloaded latest version and I going to try the same with new version.I hope it will work. I will check set loaderror call back in new test project.
Thank you
Amar Kansara
-
AuthorPosts
You must be logged in to reply to this topic.