In this article, we will see how to make an ASP GridView responsive using jQuery based Fooable plugin.
Introduction
Most of us are aware of what a responsive website is. A responsive website is a website that is compatible with different devices having different screen resolutions like desktop, laptop, tablet, mobile, etc.
The website is adapted to have best viewing experience in all the above devices without any horizontal scrollings and all. This is achieved mainly with the help of CSS, HTML 5, and jQuery.
There are a lot of plugins available for making the websites responsive and more attractive. One such plugin is Footable. It is mainly used to make table elements responsive. Before reading this article, I suggest you read my previous article which explains how to make an HTML table responsive using Footable.
Introduction
Most of us are aware of what a responsive website is. A responsive website is a website that is compatible with different devices having different screen resolutions like desktop, laptop, tablet, mobile, etc.
The website is adapted to have best viewing experience in all the above devices without any horizontal scrollings and all. This is achieved mainly with the help of CSS, HTML 5, and jQuery.
There are a lot of plugins available for making the websites responsive and more attractive. One such plugin is Footable. It is mainly used to make table elements responsive. Before reading this article, I suggest you read my previous article which explains how to make an HTML table responsive using Footable.
Now, here, we are going to make the ASP GridView control responsive.
GridView is the most commonly used way of databinding in ASP.NET websites and in this modern era of responsive websites, it has become a tough task for many developers to migrate from GridView to new responsive tables.
So here, I'm explaining a simple way to make the same GridView responsive without many changes in our code! The main advantage of this method is that this can be implemented in already integrated GridViews too!
The basic trick behind this is that the ASP GridView is rendered as an HTML table in browsers!!
First, we will start with binding an ASP GridView. Here is our sample GridView containing the data of Employees table.
GridView is the most commonly used way of databinding in ASP.NET websites and in this modern era of responsive websites, it has become a tough task for many developers to migrate from GridView to new responsive tables.
So here, I'm explaining a simple way to make the same GridView responsive without many changes in our code! The main advantage of this method is that this can be implemented in already integrated GridViews too!
The basic trick behind this is that the ASP GridView is rendered as an HTML table in browsers!!
First, we will start with binding an ASP GridView. Here is our sample GridView containing the data of Employees table.
- <asp:GridView ID="grdviewnew" runat="server" CellPadding="5" CellSpacing="0" OnRowDataBound="grd_RowDataBound"
- AutoGenerateColumns="false" CssClass="myclass" Width="100%">
- <Columns>
- <asp:TemplateField HeaderText="Employee Code" HeaderStyle-HorizontalAlign="Center">
- <ItemTemplate>
- <%#Eval("Employee Code")%>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField ItemStyle-HorizontalAlign="Left" HeaderText="Employee Name" HeaderStyle-HorizontalAlign="Center">
- <ItemTemplate>
- <%#Eval("Employee Name")%>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField ItemStyle-HorizontalAlign="Left" HeaderText="Employee Age" HeaderStyle-HorizontalAlign="Center">
- <ItemTemplate>
- <%#Eval("Employee Age")%>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField ItemStyle-HorizontalAlign="Left" HeaderText="Designation" HeaderStyle-HorizontalAlign="Center">
- <ItemTemplate>
- <%#Eval("Designation")%>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField ItemStyle-HorizontalAlign="Left" HeaderText="Experience" HeaderStyle-HorizontalAlign="Center">
- <ItemTemplate>
- <%#Eval("Experience")%>
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- </asp:GridView>
Now, we are binding this GridView from the back-end by creating a datatable.
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- BindGrid();
- }
- }
- public void BindGrid()
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("Employee Code");
- dt.Columns.Add("Employee Name");
- dt.Columns.Add("Employee Age");
- dt.Columns.Add("Designation");
- dt.Columns.Add("Experience");
- DataRow dru = dt.NewRow();
- dru["Employee Code"] = "10011";
- dru["Employee Name"] = "Rajeev";
- dru["Employee Age"] = "31";
- dru["Designation"] = "Developer";
- dru["Experience"] = "6";
- dt.Rows.Add(dru);
- dru = dt.NewRow();
- dru["Employee Code"] = "10012";
- dru["Employee Name"] = "Sandhya";
- dru["Employee Age"] = "27";
- dru["Designation"] = "Tester";
- dru["Experience"] = "2";
- dt.Rows.Add(dru);
- dru = dt.NewRow();
- dru["Employee Code"] = "10013";
- dru["Employee Name"] = "Ramesh";
- dru["Employee Age"] = "25";
- dru["Designation"] = "Designer";
- dru["Experience"] = "1";
- dt.Rows.Add(dru);
- dru = dt.NewRow();
- dru["Employee Code"] = "10014";
- dru["Employee Name"] = "Sanjay";
- dru["Employee Age"] = "32";
- dru["Designation"] = "Developer";
- dru["Experience"] = "5";
- dt.Rows.Add(dru);
- dru = dt.NewRow();
- dru["Employee Code"] = "10015";
- dru["Employee Name"] = "Ramya";
- dru["Employee Age"] = "23";
- dru["Designation"] = "Developer";
- dru["Experience"] = "1";
- dt.Rows.Add(dru);
- dt.TableName = "table1";
- grdviewnew.DataSource = dt;
- grdviewnew.DataBind();
- }







sheeraz razaPosted Feb 21, 2019, 4:54 AM
It looks like classes are not being added to <th> and <td>.
sheeraz razaPosted Feb 21, 2019, 4:53 AM
Using your sample it is working but it is not being applied on my code.
didik supriyadiPosted Oct 11, 2018, 8:40 PM
Not working in content page ...
Rinki BosePosted Aug 27, 2018, 1:32 AM
Where to make change , if i want to select the 2nd coloumn while during page responsive
Ashish DhaneshaPosted May 13, 2018, 3:32 PM
Very nice code but require same effect with database connection grid view please help...
satpal singhPosted Mar 28, 2018, 8:25 AM
In footable grid, on firing RowEditing then rowupdating event i have a text box in column whose value is '0' meanwhile it convert it to '0,0'..Please reply as soon as possible
Ashok AkkiPosted Mar 11, 2018, 10:44 PM
Grdviewnew.HeaderRow.TableSection = TableRowSection.TableHeader; error comes
Tridip BhattacharjeePosted Oct 30, 2017, 7:11 AM
Which dev tool you use to test it.......chrome?
leslie chowPosted Oct 26, 2017, 8:53 AM
Nice article on gridview. Thanks for such a nice article, there are more thing to know about gridview. I have something new on this - https://youtu.be/BA2EbZw2noM
Humayun Kabir MamunPosted Aug 26, 2017, 4:17 PM
Thanks Midhun for this nice article...
Pratik ShirsePosted Aug 23, 2017, 2:23 PM
Really good tutorial
Tridip BhattacharjeePosted Aug 23, 2017, 5:39 AM
Nice share. thanks a lot.