ASP.NET 2.0 - DataGrid with tbody / thead?

Yes, solution is described at my blog at nmarian.blogspot.com/2007/08/aspnet-data....

It can be done also via javascript. Function AddTHEAD(tableName) { var table = document. GetElementById(tableName); if(table!

= null) { var head = document. CreateElement("THEAD"); head.style. Display = "table-header-group"; head.

AppendChild(table. Rows0); table. InsertBefore(head, table.

ChildNodes0); } } Then you must call this function on body onload like that: Source: codeproject.com/KB/grid/HeaderOnEachPage....

DataGrid does not have something built-in to accomplish your needs. Take a look on ASP. NET 2.0 CSS Friendly Control Adapters 1.0 they are have built-in support for DataView, but seems you can easily adopt this idea for DataGrid.

That does gridview but not datagrid. – BC. Feb 18 '09 at 17:24 This is just an idea.

Equivalent to "Use Control Adapters" but with samples. Because this pack is open sources. Not more.

– Mike Chaliy Feb 18 '09 at 17:27.

Right, looks like the data grid doesn't support this out of the box, so I've had to create a class that inherits from the DataGrid. After the DataGrid has rendered I then parse the HTML and inject the elements in the correct place. Attached is my class for those that whant to know how.

This is a quick and dirty approach, so I'm welcome to better ideas. Imports System. IO Imports System.

Text Public Class TestDataGrid Inherits System.Web.UI.WebControls. DataGrid Private sTHeadClass As String = String. Empty Private sTBodyClass As String = String.

Empty Private sTFootClass As String = String. Empty #Region " Properties " Public Property THeadClass() As String Get Return sTHeadClass End Get Set(ByVal value As String) sTHeadClass = value End Set End Property Public Property TBodyClass() As String Get Return sTBodyClass End Get Set(ByVal value As String) sTBodyClass = value End Set End Property Public Property TFootClass() As String Get Return sTFootClass End Get Set(ByVal value As String) sTFootClass = value End Set End Property #End Region Protected Overrides Sub Render(ByVal writer As System.Web.UI. HtmlTextWriter) Dim oMemoryStream As New MemoryStream() Dim oStreamWriter As New StreamWriter(oMemoryStream) Dim oStreamReader As New StreamReader(oMemoryStream) Dim oHtmlTextWriter As New HtmlTextWriter(oStreamWriter) MyBase.

Render(oHtmlTextWriter) oHtmlTextWriter.Flush() oMemoryStream.Flush() oMemoryStream. Position = 0 Dim sHtml As String = oStreamReader.ReadToEnd() Dim oHtml As New Text.StringBuilder() Dim iPastIndex As Integer = 0 Dim iIndex As Integer = sHtml. IndexOf("") oHtml.

Append(sHtml. Substring(iPastIndex, iIndex - iPastIndex)) iPastIndex = iIndex If ShowHeader Then WriteElementStart(oHtml, "thead", sTHeadClass) 'Write Header Row iIndex = sHtml. IndexOf("", iPastIndex) + 5 oHtml.

Append(sHtml. Substring(iPastIndex, iIndex - iPastIndex)) iPastIndex = iIndex oHtml. Append("") WriteElementStart(oHtml, "tbody", sTBodyClass) Else WriteElementStart(oHtml, "tbody", sTBodyClass) End If If ShowFooter Then 'Writer Body Rows iIndex = sHtml.

LastIndexOf("") oHtml. Append(sHtml. Substring(iPastIndex, iIndex - iPastIndex)) iPastIndex = iIndex WriteElementEnd(oHtml, "tbody") WriteElementStart(oHtml, "tfoot", sTFootClass) 'Write Footer Row iIndex = sHtml.

LastIndexOf("") oHtml. Append(sHtml. Substring(iPastIndex, iIndex - iPastIndex)) iPastIndex = iIndex WriteElementEnd(oHtml, "tfoot") Else iIndex = sHtml.

LastIndexOf("") oHtml. Append(sHtml. Substring(iPastIndex, iIndex - iPastIndex)) iPastIndex = iIndex WriteElementEnd(oHtml, "tbody") End If oHtml.

Append(sHtml. Substring(iPastIndex, sHtml. Length - iPastIndex)) writer.

Write(oHtml.ToString()) End Sub Private Sub WriteElementStart(ByVal Builder As StringBuilder, ByVal Tag As String, ByVal CssClass As String) If String. IsNullOrEmpty(CssClass) Then Builder. AppendFormat("", Tag) Else Builder.

AppendFormat("", Tag, CssClass) End If End Sub Private Sub WriteElementEnd(ByVal Builder As StringBuilder, ByVal Tag As String) Builder. AppendFormat("", Tag) End Sub End Class.

Sorry, but I do not like this solution. For example it depends on HtmlWriter used. With UpperCaseHtmlWriter your solution will not work.

Also code with MemoryStream... Also HtmlTextWriter... – Mike Chaliy Feb 18 '09 at 20:22 Could you explain further? The Render method of the control expets an HtmlTextWriter as an input, it's in the definition! What is your objection to MemoryStream, etc.– Ady Feb 19 '09 at 1:52.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions