How To Render Thead and Tbody tag in GridView

In this post i am going to share tips and tricks about how to generate Thead and Tbody in gridview because default GridView in generate table>tr>th type of structure. uncomment this statement and see the result //Uncomment this line for THEAD and TBODY //grdPage.HeaderRow.TableSection = TableRowSection.TableHeader;

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<form id="form1" runat="server">
   <asp:GridView ID="grdPage" runat="server">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)

   grdPage.DataSource = new Person().GetAll();
   //Uncomment this line for  THEAD and TBODY
   //grdPage.HeaderRow.TableSection = TableRowSection.TableHeader;

class Person
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public List<Person> GetAll()

   List<Person> list = new List<Person>()
       new Person{Id=1,FirstName="Barak",LastName="Obama",Age=41},
       new Person{Id=2,FirstName="Scott",LastName="Allen",Age=43},
       new Person{Id=3,FirstName="Bill",LastName="Gates",Age=21},
       new Person{Id=4,FirstName="Name",LastName="LastName",Age=21},
   return list;


No comments:

Post a Comment