0

I'm trying to get footable working with my asp.net gridview. I have followed every ASP.NET guide on the internet for footable and nothing seems to work.

Gridview ASP Markup

<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>

Code Behind File

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();
});

If anyone has any idea that would be amazing.

Mike
  • 850
  • 10
  • 33
TobusBoulton
  • 181
  • 1
  • 14

2 Answers2

0

Create java script function for footable name as "applyFootable" and call this on page load from java script as below:

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

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

OR

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

And same you need to call from your code behind page (on Page Load Event) using ScriptManager.RegisterStartupScript as below:

protected void Page_Load(object sender, EventArgs e)
{

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

}

Try this, it was worked for me.

0

Here, I explained with an example, how to make ASP.Net GridView responsive with jQuery Footable using C#.

A responsive GridView will adjust itself to look in Mobile Phone, Tablet and Desktop displays in ASP.Net.

.Aspx Page

<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 Page

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";

Try this, That was really helped me.

Disha Sojitra
  • 9
  • 1
  • 1
  • 5