I have created a DataTable from a SQL query in the the controller.
How do I "connect" '#example' with 'categories'?
EDIT1: After suggestion to use jQuery.DataTables
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Employee Index Page</title>
</head>
<body>
<div>
<h1>Employee Index Page</h1>
<table id="example">
</div>
</body>
</html>
@{ var categories = (System.Data.DataTable)ViewData["MyData"]; }
<script>
$(document).ready(function () {
$('#example').DataTable();
});
</script>
ORIGINAL
I want to assign this to a gridview. The Code from the View is below but GridView1 needs to be defined somehow.
In the c# categories has the right contents, but GridView1 get the error "does not exist in the current context".
How and where do I fix that?
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Employee Index Page</title>
</head>
<body>
<div>
<h1>Employee Index Page</h1>
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat="server" DataSource='<%# GetData() %>' AutoGenerateColumns="true">
</asp:GridView>
@{
var categories = (System.Data.DataTable)ViewData["MyData"];
GridView1.DataSource = categories;
GridView1.DataBind();
}
</div>
</body>
</html>