Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #########################################
- // Default.aspx.cs File
- // #########################################
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Reflection;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- myDataGrid dg = new myDataGrid();
- dg.DataSource = new string[] { "1", "2", "3", "4", "5", "6" };
- dg.DataBind();
- ph.Controls.Add(dg);
- }
- }
- }
- public class myDataGrid : System.Web.UI.WebControls.DataGrid
- {
- protected override void OnPreRender(EventArgs e)
- {
- Table table = Controls[0] as Table;
- if (table != null && table.Rows.Count > 0)
- {
- // first row is the Table Header <thead>
- table.Rows[0].TableSection = TableRowSection.TableHeader;
- // last row is the Footer Header <tfoot> (comment for not using this)
- table.Rows[table.Rows.Count - 1].TableSection = TableRowSection.TableFooter;
- FieldInfo field = typeof(WebControl).GetField("tagKey", BindingFlags.Instance | BindingFlags.NonPublic);
- foreach (TableCell cell in table.Rows[0].Cells)
- field.SetValue(cell, HtmlTextWriterTag.Th);
- }
- base.OnPreRender(e);
- }
- }
- <!--
- // #########################################
- // Default.aspx File
- // #########################################
- -->
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>DataGrid with thead and tfoot Example</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <h1>
- DataGrid example</h1>
- <asp:PlaceHolder ID="ph" runat="server" />
- </div>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement