You can easily do using the jQuery Responsive Table Plugin.
Download the XML file from here.
http://aspsnippets.com/DownloadFile.aspx?File=Customers.xml
And then use the following code
HTML
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
table
{
border:1px solid #ccc;
}
table th
{
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
table th, table td
{
padding: 5px;
border-color: #ccc;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type = "text/javascript" src = "http://declanbright.awardspace.info/download/jquery.responsivetable.min.js"></script>
<script type = "text/javascript">
$(function () {
$('#GridView1').responsiveTable({
staticColumns: 2,
scrollRight: true,
scrollHintEnabled: true,
scrollHintDuration: 2000
});
});
</script>
Namespaces
using System.Data;
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/Customers.xml"));
GridView1.DataSource = ds.Tables[0].Rows.Cast<DataRow>().Take(5).CopyToDataTable();;
GridView1.DataBind();
}
}