我正试图使用我的asp.net gridview。我已经关注了互联网上的每个ASP.NET指南,并且似乎没有任何效果。
Gridview ASP标记
<asp:GridView ID="GridView1" runat="server" CssClass="footable" AutoGenerateColumns="false" OnRowCommand="GridView1_RowCommand" DataKeyNames="ClientID" DataSourceID="SqlDataSource1" Style="max-width: 1024px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ClientID" HeaderText="Client ID" InsertVisible="False" ReadOnly="True" SortExpression="ClientID" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" />
<asp:BoundField DataField="Suburb" HeaderText="Suburb" SortExpression="Suburb" />
<asp:BoundField DataField="MobileNumber" HeaderText="Mobile Number" SortExpression="MobileNumber" />
</Columns>
</asp:GridView>
文件后面的代码
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
GridView1.HeaderRow.Cells[0].Attributes["data-class"] = "expand";
GridView1.HeaderRow.Cells[2].Attributes["data-hide"] = "phone, tablet";
JS
<script type="text/javascript">
$(function () {
$('[id*=GridView1]').footable();
});
如果有人有任何想法会很棒。
答案 0 :(得分:0)
将footable name的java脚本函数创建为“applyFootable”,并在java脚本的页面加载中调用此函数,如下所示:
<script type="text/javascript">
$(function () {
applyFootable();
});
function applyFootable() {
$('[id*=GridView1]').footable();
}
OR
function applyFootable(){
$('.footable').footable();
}
同样需要使用ScriptManager.RegisterStartupScript从页面后面的代码(在页面加载事件上)调用,如下所示:
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "applyFootable", "applyFootable();", true);
}
试试这个,它对我有用。
答案 1 :(得分:0)
在这里,我通过一个示例解释了如何使用C#使jQuery Footable响应ASP.Net GridView。
响应式GridView会自动调整以在ASP.Net中的手机,平板电脑和台式机显示器中显示。
.aspx页面
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-footable/0.1.0/css/footable.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-footable/0.1.0/js/footable.min.js"></script>
<script type="text/javascript">
$(function () {
$('[id*=DataGridView]').footable();
});
</script>
<asp:GridView ID="DataGridView" CssClass="footable" runat="server" AutoGenerateColumns="false" Style="max-width: 500px">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Customer Id" />
<asp:BoundField DataField="Name" HeaderText="Customer Name" />
<asp:BoundField DataField="City" HeaderText="City" />
</Columns>
</asp:GridView>
.Aspx.cs页面
Bind.BindGridView(DataGridView, actionResult.dtResult);
if (DataGridView.Rows.Count > 0)
{
DataGridView.HeaderRow.TableSection = TableRowSection.TableHeader;
}
DataGridView.HeaderRow.Cells[0].Attributes["data-class"] = "expand";
DataGridView.HeaderRow.Cells[1].Attributes["data-hide"] = "phone";
DataGridView.HeaderRow.Cells[2].Attributes["data-hide"] = "phone";
尝试一下,那真的帮助了我。