jQWidgets Forums
jQuery UI Widgets › Forums › General Discussions › ASP .NET MVC › jqxGrid – asp.net MSSQL data binding no data to display
Tagged: jqxGrid ;, mssql data binding
This topic contains 1 reply, has 2 voices, and was last updated by admin 7 years, 8 months ago.
Viewing 2 posts - 1 through 2 (of 2 total)
-
Author
-
I have followed the example(s) and have altered the code to try and display the data from a SQL data table called Budgets
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Services; using System.Web.Script.Services; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web.Script.Serialization; namespace PurReq.testing { public partial class jqxGrid : System.Web.UI.Page { //variables etc... // cnnection string string constr = ConfigurationManager.ConnectionStrings["PurReq"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { } [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)] public static string GetBudget() { string query = "SELECT * FROM Budgets"; SqlCommand comm = new SqlCommand(query); //populate the dataset DataSet data = GetData(comm); // return the udget 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 comm) { string constr = ConfigurationManager.ConnectionStrings["PurReq"].ConnectionString; using(SqlConnection conn = new SqlConnection(constr)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { comm.Connection = conn; sda.SelectCommand = comm; using(DataSet ds = new DataSet()) { sda.Fill(ds); return ds; } } } } } }
aspx file:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="jqxGrid.aspx.cs" Inherits="PurReq.testing.jqxGrid" %> <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <!-- javascript here --> <link href="../jqWidgets/styles/jqx.base.css" rel="stylesheet" type="text/css" /> <link href="../jqWidgets/styles/jqx.darkblue.css" rel="stylesheet" type="text/css" /> <script src="../jqWidgets/jquery-1.11.1.min.js" type="text/javascript"></script> <script src="../jqWidgets/jqxcore.js" type="text/javascript"></script> <script src="../jqWidgets/jqxbuttons.js" type="text/javascript"></script> <script src="../jqWidgets/jqxdata.js" type="text/javascript"></script> <script src="../jqWidgets/jqxgrid.js" type="text/javascript"></script> <script src="../jqWidgets/jqxgrid.selection.js" type="text/javascript"></script> <script src="../jqWidgets/jqxmenu.js" type="text/javascript"></script> <script src="../jqWidgets/jqxscrollbar.js" type="text/javascript"></script> <!-- --> <script type="text/javascript"> $(document).ready(function () { //Getting the source data with ajax GET request source = { datatype: "xml", datafields: [ { name: 'BudgetID' }, { name: 'BudgetNameID' } ], async: false, record: 'Table', url: 'jqxGrid.aspx/GetBudget' }; var dataAdapter = new $.jqx.dataAdapter(source, { contentType: 'application/json; charset=utf-8'} ); $("#jqxgrid").jqxGrid({ source: dataAdapter, theme: 'darkblue', columns: [ { text: 'ID', dataField: 'BudgetID', width: 250 }, { text: 'Name', dataField: 'BudgetNameID', width: 100 } ] }); }); </script> <!-- place grid here --> <div id="jqxgrid"></div> </asp:Content>
The grid renders ok but with no data – can anyone see why this is, any help would be appreciated
Andy
Hi aquaAndy,
Your dataType is ‘xml’ and your contentType is JSON. I would suggest you to double check this on your side.
Best Regards,
Peter StoevjQWidgets Team
https://www.jqwidgets.com -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.