0

I'm working on displaying tabular data from a SQL database in a 'aspx' page that I added into an mvc template project I have made inside Visual Studio 2013.

I have a SQL DataSource connected to a database bringing back a basic table. I can display the information in the 'DataTable.aspx' file. I am not able to get the dataTables.js or the .css files to run. Or I do not think that they are running. This is what I have checked so far..

  • I can see jquery as having loaded, and I did install both jquery and datatables in the 'NuGet' package manager through Visual Studio 2013 (demo)
  • The .net tab in FireFox (sometimes shows that the .js and .cs files in the debug session in black or gray.
    -I think my 'DataTables.aspx' file is correct (below).

    <%: Title %>.

    TaskTable

    <div>  
         <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
             ConnectionString="<%$ ConnectionStrings:TaskRFIDatabaseConnectionString %>"
             SelectCommand="SELECT [TaskID], [TaskTypeID], [TaskCreatedBy], [TaskName], [TaskDescription], [TaskCreatedDateTime] FROM [TaskTable]">
         </asp:SqlDataSource>
         <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
             <HeaderTemplate>
                 <table id="DataTable">
                    <thead>
                    <tr>
                        <th>TaskID</th>
                        <th>TaskTypeID</th>
                        <th>TaskCreatedBy</th>
                        <th>TaskName</th>
                        <th>TaskDescription</th>
                        <th>TaskCreatedDateTime</th>                        
                    </tr>
                    </thead>
             </HeaderTemplate>
             <ItemTemplate>
                <tr>
                    <td><%# Eval("TaskId") %></td>
                    <td><%# Eval("TaskTypeID") %></td>
                    <td><%# Eval("TaskCreatedBy") %></td>
                    <td><%# Eval("TaskName") %></td>
                    <td><%# Eval("TaskDescription") %></td>
                    <td><%# Eval("TaskCreatedDateTime") %></td> 
                </tr>            
             </ItemTemplate>
             <FooterTemplate>
                 </table>
             </FooterTemplate>
        </asp:Repeater>          
    </div> 
    

The site master has the references to the .js and .css files for dataTables.

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="Compass.SiteMaster" %>

<!DOCTYPE html>

<html lang="en">
<head runat="server">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title><%: Page.Title %> - Compass</title>
    <link href="Content/DataTables-1.10.3/css/jquery.dataTables.css" rel="stylesheet" />
    <script src="Scripts/jquery-2.1.1.js"></script>
    <script src="Scripts/DataTables-1.10.3/media/js/jquery.dataTables.js"></script>
    <asp:PlaceHolder runat="server">
        <%: Scripts.Render("~/bundles/modernizr") %>
    </asp:PlaceHolder>
    <webopt:bundlereference runat="server" path="~/Content/css" />   
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />

</head>

<body>
    <form runat="server">
        <asp:ScriptManager runat="server">
            <Scripts>
                <%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%>
                <%--Framework Scripts--%>
                <asp:ScriptReference Name="MsAjaxBundle" />
                <asp:ScriptReference Name="jquery" />

                <asp:ScriptReference Name="bootstrap" />
                <asp:ScriptReference Name="respond" />                  
                <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
                <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
                <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
                <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
                <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
                <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
                <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
                <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
                <asp:ScriptReference Name="WebFormsBundle" />

                <%--Site Scripts--%>
            </Scripts>
        </asp:ScriptManager>

        <div class="navbar navbar-inverse navbar-fixed-top">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" runat="server" href="~/">Application name</a>
                </div>
                <div class="navbar-collapse collapse">
                    <ul class="nav navbar-nav">
                        <li><a runat="server" href="~/">Home</a></li>
                        <li><a runat="server" href="~/About">About</a></li>
                        <li><a runat="server" href="~/Contact">Contact</a></li>
                        <li><a runat="server" href="~/DataTable">DataTable</a></li>
                    </ul>
                    <asp:LoginView runat="server" ViewStateMode="Disabled">
                        <AnonymousTemplate>
                            <ul class="nav navbar-nav navbar-right">
                                <li><a runat="server" href="~/Account/Register">Register</a></li>
                                <li><a runat="server" href="~/Account/Login">Log in</a></li>
                            </ul>
                        </AnonymousTemplate>
                        <LoggedInTemplate>
                            <ul class="nav navbar-nav navbar-right">
                                <li><a runat="server" href="~/Account/Manage" title="Manage your account">Hello, <%: Context.User.Identity.GetUserName()  %> !</a></li>
                                <li>
                                    <asp:LoginStatus runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" OnLoggingOut="Unnamed_LoggingOut" />
                                </li>
                            </ul>
                        </LoggedInTemplate>
                    </asp:LoginView>
                </div>
            </div>
        </div>

        <div class="container body-content">
            <asp:ContentPlaceHolder ID="HeaderContent" runat="server">
                <link href="Content/DataTables-1.10.3/css/jquery.dataTables.css" rel="stylesheet" />
                <script src="Scripts/jquery-2.1.1.js"></script>
                <script src="Scripts/DataTables-1.10.3/jquery.dataTables.js"></script>
            </asp:ContentPlaceHolder>
            <asp:ContentPlaceHolder ID="MainContent" runat="server">
            </asp:ContentPlaceHolder>
            <hr />
            <footer>
                <p>&copy; <%: DateTime.Now.Year %> - My ASP.NET Application</p>
            </footer>
        </div>
    </form>
</body>
</html>

Where else would you check? All of the examples I have read have been either dealing with a simple page or are using different methods. This is from a base web/mvc template from Visual Studio 2013 and jQuery dataTables.js installed through NuGet.

Some of the other pages I have already hit: jQuery DataTable not working in asp.net mvc 4

http://www.codeproject.com/Articles/155422/jQuery-DataTables-and-ASP-NET-MVC-Integration-Part

Is there anyplace else I should be looking? Andy..

2
  • 1
    You should seriously consider a better title for your question. Please choose a name that describes the problem you are having. You don't even mention css and javascript at all in there. Commented Nov 3, 2014 at 20:26
  • Yep. Hopefully this will be better Commented Nov 3, 2014 at 20:29

1 Answer 1

0

Woo Hoo.. Found it.

I'm learning the ropes in the world of MVC 5 and jQuery/dataTables.

Let me restate the problem: I had a VS(2013) project (Web / .NetFramework4.5.1 / ASP.NET Web Application / WebForms (checkd 'WebForms', MVC)) I added in the references for jQuery & DataTables through the NuGet Package Manager. wrongly thought that this magically put all of the references I needed for the wireup

I added the following objects via drag drop to the cookie cutter template I used above from Data toolbox:

  1. Repeater (source set to the 'SqlDataSource1')
  2. SqlDataSource (setup with connection to my database)

So I thought I had all of the jQuery / js / css for using DataTables. I have done this in straight javascript before (Aptana) and could not figure out where the references for the css would have to be inserted. I about drove me crazy.

I know, get to it.. The scripts were there but not really doing anything. A table was generated but didn't have the css or scripty goodness that I wanted. That was the problem no css or script behavior I expected from dataTables.

What I did: 1. Started over with a new project, Added jQuery and DataTables through NuGet Package Manager. 2. Opened up "Site.Master" file and added references to the css in the section

<Link href="Content/DataTables-1.10.3/css/jquery.dataTables.css" rel="stylesheet"/>
  1. Added the reference to the jquery.dataTables.js file in the same file "Site.Master"..

    <asp:ScriptManager runat="server">
        <Scripts>       
            <%--Framework Scripts--%>
            <asp:ScriptReference Name="MsAjaxBundle" />
            <asp:ScriptReference Name="jquery" />
            <asp:ScriptReference Path="~/Scripts/DataTables-1.10.3/jquery.dataTables.js" />
            <asp:ScriptReference Name="bootstrap" />
            <asp:ScriptReference Name="respond" />
            <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
            <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
            <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
            <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
            <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
            <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
            <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
            <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
            <asp:ScriptReference Name="WebFormsBundle" />
            <%--Site Scripts--%>
        </Scripts>
    </asp:ScriptManager>
    
  2. Cleaned / Rebuilt project

  3. Added the final script call to the aspx page (final markup below)

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="maybe._Default" %> StaffID LName FName WorkPhone
    <%# Eval("StaffID") %> <%# Eval("LName") %> <%# Eval("FName") %> <%# Eval("WorkPhone") %>

    "myselection text">

    $('#DataTable').dataTable();

Rebuilt and then ran it .. Worked!!. Andy

sources: http://www.youtube.com/watch?v=bfCLyaWHvcM Sql Repeater
http://msdn.microsoft.com/en-us/library/bb398991%28v=vs.100%29.aspx

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.