Quantcast
Viewing all articles
Browse latest Browse all 82126

Error with C#: This XML file does not appear to have any style information associated with it.

Hello everyone,
I am currently trying to use DataTables in an application where I work. I am building the application using C# and ASP.NET, and am trying to make a DataTables user control that I can just add to any web page. I have most of it working, but I keep coming across this error whenever I try and generate the tables. It just hangs in the processing loop, and I had to open up the console in Chrome to find this error:


This XML file does not appear to have any style information associated with it. The document tree is shown below.
<string xmlns="http://tempuri.org/"&gt;
{"sEcho": "1","iTotalRecords": 8,"iTotalDisplayRecords": 8, "aaData": [ ALL OF MY TABLE ROWS ARE HERE ARE IN HERE...]}
</string>

Here is a link to a zipped folder of the solution: https://dl.dropboxusercontent.com/u/46643291/DataTableCSharp.zip. It is a VS2012 solution.
Here are the relevant pieces of code:

JQueryDatatable.ascx.cs:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DataTableCSharp {
    public partial class JQueryDataTable : System.Web.UI.UserControl {
        protected void Page_Load(object sender, EventArgs e) {

            Table HeaderTable = new Table();
            HeaderTable.ID = "sampleTable";
            HeaderTable.CssClass = "widthFull fontsize10 displayNone";

            string tableName = "Table";
            string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(string.Empty) + @"\App_Data\TestDB.accdb";
            string sqlString = "SELECT Table.* FROM [" + tableName +"]";
            OleDbConnection connect = new OleDbConnection(conString);
            DataSet ds = new DataSet();
            OleDbDataAdapter adapter = new OleDbDataAdapter(sqlString, connect);
            adapter.Fill(ds);
            CreateHTMLTable(ds.Tables[0]);
            
        }


        private void WriteComment(String comment, HtmlTextWriter writer) {
            writer.Write("\n<!-- " + comment + " -->\n");
        }

        public void CreateHTMLTable(DataTable table) {
            Table htable = new Table();
            htable.Attributes.Add("class", "widthFull fontsize10 displayNone");
            htable.ID = "sampleTable";
            TableRow row = new TableRow();
            int count = 1;
            row.TableSection = TableRowSection.TableHeader;
            foreach (DataColumn column in table.Columns) {
                TableCell cell = new TableCell();
                cell.Text = column.ColumnName;
                row.Cells.Add(cell);
                if (count++ >= 5) break;
            }
            htable.Rows.Add(row);
            tableDiv.Controls.Add(htable);
        }
    }
}

JQueryDataTable.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="JQueryDataTable.ascx.cs" Inherits="DataTableCSharp.JQueryDataTable" %>


    <style>
        .widthFull
        {
            width: 100%;
        }

        .fontSize10
        {
            font-size: 10px;
        }
        .displayNone
        {
            display:none;
        }
    </style>

    <script src="Scripts/jquery-1.8.1.min.js"></script>
    <script src="Scripts/jquery-ui-1.8.23.min.js"></script>
    <script src="Scripts/jquery.json-2.3.min.js"></script>
    <script src="Scripts/DataTables/jquery.dataTables.js"></script>
    <link href="Content/DataTables/css/demo_table_jui.css" rel="stylesheet" />
    <link href="Content/themes/base/jquery.ui.all.css" rel="stylesheet" />


        <div>
            Click to load table 
           <button id="get">LoadTable</button>
        </div>
        <div id="tableDiv" style="width:1500px" runat="server">

        </div>
 


<script>
    $(document).ready(function () {
        $("#get").click(function (e) {
            
            e.preventDefault();
            getTable();
            
        });
    });


    var getTable = function () {

        $("#FeaturedContent_DataTable_sampleTable").dataTable({
            "oLanguage": {
                "sZeroRecords": "No records to display",
                "sSearch": "Search"
            },
            "aLengthMenu": [[2, 5, 10, 20, 25, 50, 100, 150, 250, 500, -1], [2, 5, 10, 20, 25, 50, 100, 150, 250, 500, "All"]],
            "iDisplayLength": 20,

            "bSortClasses": false,
            "sScrollY": 800,
            "sScrollX": 1500,

            "bScrollCollapse": true,
            "bStateSave": false,
            "bPaginate": true,
            "bAutoWidth": true,
            "bProcessing": true,
            "bServerSide": true,
            "bDestroy": true,
            "sAjaxSource": "TableService.asmx/GetItems",
            "bJQueryUI": true,
            "sPaginationType": "full_numbers",
            "sServerMethod": "GET",
            "bDeferRender": true,
            "fnServerData": function (sSource, aoData, fnCallback) {
                $.ajax({
                    
                    "dataType": 'json',
                    "contentType": "application/json",
                    "type": "GET",
                    "url": sSource,
                    "data": aoData,
                    "success":
                                function (msg) {
                                    var json = jQuery.parseJSON(msg.d);
                                    fnCallback(json);
                                    $("#FeaturedContent_DataTable_sampleTable").show();
                                }
                });
                
            }
        });
    }
</script>

More below...

Viewing all articles
Browse latest Browse all 82126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>