-
Customizing DataGrid (or any control)
Hi, I have to customize a datagrid so that I can have the headers shows up in TH tag instead of TD tag and a few other things that are coming down the road so that those tables are accessible. I searched online and found an example which I was able to use but it's not doing what i want to do the proper (dynamic) way.
For now this is what I have: a class which Inherits System.Web.UI.WebControls.DataGrid
Code:
Protected Overloads Overrides Sub Render(ByVal output As HtmlTextWriter)
If Not Visible Then
Return
End If
Dim writer As StringWriter = New StringWriter
Dim buffer As HtmlTextWriter = New HtmlTextWriter(writer)
MyBase.Render(buffer)
Dim gridMarkup As String = writer.ToString
Dim insertPoint As Integer
'grab first instance of TR and closing TR
Dim intStartTR, intEndTR As Integer
intStartTR = gridMarkup.IndexOf("<tr>")
intEndTR = gridMarkup.IndexOf("</tr>")
Dim strHeadRow As String = gridMarkup.Substring(intStartTR, intEndTR - intStartTR)
'replace all TDs that occur in between first TRs with TH
strHeadRow = strHeadRow.Replace("<td", "<th scope=""col"" ")
strHeadRow = strHeadRow.Replace("</td>", "</th>")
gridMarkup = gridMarkup.Remove(intStartTR, intEndTR - intStartTR)
gridMarkup = gridMarkup.Insert(intStartTR, strHeadRow)
'end adding TH
output.Write(gridMarkup)
End Sub
The code above does what I want to do for now but as you can see it is sort of a static way of doing things. If I wanted to add something to the TH tag, I would have to add it here and then recompile the code and so on.
What I really want to do here is be able to create some custom properties (which will become attributes for TABLE) which can be assigned in the asp:TemplateColumn tags and then call them either in this Render or any other method to add them as attributes (headers, ID, etc).
I tired doing this (changing TD to TH for header items) in the code behind for ASPX page but I didn't get anywhere:
Code:
Private Sub onBound(ByVal o As Object, ByVal e As DataGridItemEventArgs) Handles dg2.ItemDataBound
If e.Item.ItemType = ListItemType.Header Then
Dim ctr As Control
For Each ctr In e.Item.Controls
'e.Item.RenderControl doesn't do anything
Next
End If
End Sub
I know what I am asking for might be idiotic or just not possible but I dont see anyother way of getting the functionality of datagrid (without spending a whole lot of time) and yet still make it accessible. Thanks in advance for any help.
new to programming but getting ther
-
Can you do your project in ASP.NET 2.0? It includes a number of improvements for creating accessible Web sites: http://www.15seconds.com/issue/040727.htm
If not, it looks like there's a patch available for the 1.1 datagrid: http://www.hanselman.com/blog/Sectio...AndASPNET.aspx
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
thanks Phill. Unfortunately (or maybe it was planned, hmmm) every programmer got VS2005 a lonnnngggg time ago before me. And I haven't even started playing with it yet.
Thanks for the link but I am still out of luck for being able to do anything (any customization to add whatever I want to add) regarding the DataGrid class, aren't I?
new to programming but getting ther
-
Use css for it. Create a style and then set the datagrids style to it. There are multiple styles for parts like the header, footer, etc.
-
Yes, to control the style I am using CSS at many other places but style sheet will only handle the formatting, it's not going to handle the HTML output of the datagird. I am looking for a way to control the HTML output.
new to programming but getting ther
Similar Threads
-
By V Lakshmi Narasimhan in forum ASP.NET
Replies: 1
Last Post: 07-19-2006, 01:55 PM
-
Replies: 0
Last Post: 08-22-2005, 03:41 AM
-
By Raymond Naseef in forum ASP.NET
Replies: 0
Last Post: 03-21-2002, 12:22 PM
-
By David Livingston in forum ASP.NET
Replies: 2
Last Post: 01-26-2001, 03:17 PM
-
By Sok Y. Kim in forum VB Classic
Replies: 0
Last Post: 10-25-2000, 07:19 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks