GridView using a custom Template deriving from ITemplate to apply dynamic XSLT formatting?

  • Thread starter Tobias Zimmergren
  • Start date
T

Tobias Zimmergren

Hi,

I've developed a WebPart which renders a SPGridView (A SharePoint control
deriving from the normal GridView) which is hooking up one
column that is based on my custom coded TemplateField which derives from
"ITemplate".
So far so good, when I fill a DataTable and loads it with some data and then
use myGrid.DataSource = myDataTable; and myGrid.DataBind();
it all works!

My custom TemplateField works wonders and I now get a very very unique
design of the SPGridView. However, in my customly created TemplateField the
html that formats the column is hard-coded into the C# code.

What would be the best way to dynamically load some kind of XSL Template to
use instead of the hard-coded HTML to use in my class deriving from
ITemplate?

If one would use XSLT instead of hardcoding it in, the
administrator/deployer/designer can create a custom/modified look and feel
for the TemplateField column which would lead to a much more manageable
solution.

/* An example of what I'm doing to my SPGridView in order to hook up my
custom TemplateField */
TemplateField mainColumn = new TemplateField();
mainColumn.HeaderTemplate = new MainTemplate(ListItemType.Header, "Forum
Header");
mainColumn.ItemTemplate = new MainTemplate(ListItemType.Item, "Forum
Item");
mainColumn.AlternatingItemTemplate = new
MainTemplate(ListItemType.AlternatingItem, "Forum Item");
mainColumn.FooterTemplate = new MainTemplate(ListItemType.Footer, "Forum
Footer");
gvOverview.Columns.Add(mainColumn);
/* End example */

So, does anyone have any experience with using this kind of approach?
Let me know if I need to elaborate this more.

Cheers, and good weekend!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top