0

我正在尝试使用我的 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();
});

如果有人有任何想法,那将是惊人的。

4

2 回答 2

0

为footable名称创建java脚本函数为“applyFootable”,并在页面加载时从java脚本调用它,如下所示:

<script type="text/javascript">
$(function () {
    applyFootable();
}); 

function applyFootable() {
    $('[id*=GridView1]').footable();
}

或者

function applyFootable(){
     $('.footable').footable();
}

同样,您需要使用 ScriptManager.RegisterStartupScript 从页面后面的代码(在页面加载事件上)调用,如下所示:

protected void Page_Load(object sender, EventArgs e)
{

   ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "applyFootable", "applyFootable();", true);

}

试试这个,它对我有用。

于 2016-01-18T14:36:03.530 回答
0

在这里,我用一个例子解释了如何使用 C# 使 ASP.Net GridView 响应 jQuery Footable。

响应式 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";

试试这个,这对我很有帮助。

于 2019-06-17T11:11:46.520 回答