【发布时间】:2016-10-28 22:01:32
【问题描述】:
我已经从控制器中的 SQL 查询创建了一个 DataTable。
如何将“#example”与“categories”“联系起来”?
EDIT1:建议使用 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>
原创
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>
【问题讨论】:
-
你为什么在 MVC 中使用 asp:gridview?
-
网络搜索表明这是一种显示数据表的简单方法。我对替代品持开放态度!
-
就个人而言,我会考虑将数据表(或类似的)与 MVC codeproject.com/Articles/155422/…
-
你不能混合 ASP 控件和 MVC 我很确定(老实说我从没想过尝试......)
-
你可以做一个普通的 HTML
<table>和 for-loop 遍历所有的标题、列、行等......
标签: c# jquery asp.net-mvc