Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsReportsReportsUse the ASPNET Css Friendly Adapters 1.0 and Export to ExcelUse the ASPNET Css Friendly Adapters 1.0 and Export to Excel
Previous
 
Next
New Post
1/17/2011 5:09 PM
 

    I want to make the Reports module grid visualizer display a little bit easier, so I will use the ASPNET Css Friendly Adapters 1.0, and Matt Berseth's http://mattberseth.com/blog/2007/04/e... to export grid report to Excel.  I will show you the steps to set it up.  Please try with the development site first before put these to the production server.

    1. Make sure the Reports Module must be installed to your DNN website, create a report from Reports module, select the Grid Visualizer from the Active Visualizer dropdownlist.  You can select the option Enable Paging, Enable Sorting and view your report.

    2. Download the ASPNET CSS Friendly Adapters from Microsoft website http://download.microsoft.com/downloa..., then run the CSS Friendly Adapter vsi. 

    3. Extract the C:\Users\YourUserName\Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual Web Developer\VisualBasic\ASPNETCssFriendlyAdaptersVB.zip to a temporary folder.  From the temporary folder, copy folders App_Browsers, App_Code, App_Themes, CSS, and JavaScript to DNN root folder, overwrite existing data (actually, there is no overwrite)

    4. Download the CSS Friendly Adapters from http://cssfriendly.codeplex.com/relea..., extract to temporary folder

    5. From Visual Studio, add reference from temporary folder/CSSFriendly.dll and temporary folder\bin\Wilco.SyntaxHighlighter.dll

    6. From Visual Studio, add the content listed below at the end of your DNN/Portals/_default/Default.css (this will include the CSS Class "PrettyGridView")

01..foo {} /* W3C CSS validator likes CSS files to start with a class rather than a comment. Soooooo.... */
02.  
03./* This style sheet is intended to contain OFTEN CHANGED rules used when the GridView control adapter is enabled. */
04./* Empty rules are provided merely as a convenience for your future use or experimentation. */
05.  
06..PrettyGridView .AspNet-GridView
07.{
08.    width: 100%;
09.  
10.    font-family:lucida grande,arial,helvetica,sans-serif;
11.    font-size:14px;
12.    background-color:#fff;
13.    /* 
14.    border:solid 2px #000;
15.    padding:4px;
16.    */
17.}
18.  
19..PrettyGridView .AspNet-GridView div.AspNet-GridView-Pagination,
20..PrettyGridView .AspNet-GridView div.AspNet-GridView-Pagination a,
21..PrettyGridView .AspNet-GridView div.AspNet-GridView-Pagination span
22.{
23.    color: #00FFFF;
24.    background: #284775;
25.    font-weight: normal;
26.    padding: 2px;
27.}
28.  
29..PrettyGridView .AspNet-GridView table
30.{
31.    border: solid 1px #CCCCCC;
32.    width: 100%;
33.}
34.  
35..PrettyGridView .AspNet-GridView table thead tr th
36.{
37.    color: #F7F6F3;
38.    background: #5D7B9D;
39.    font-weight: bold;
40.    border-bottom: solid 1px #CCCCCC;
41.    border-right: solid 1px #CCCCCC;
42.    padding: 2px;
43.}
44.  
45..PrettyGridView .AspNet-GridView table thead tr th a
46.{
47.    color: #F7F6F3;
48.}
49.  
50..PrettyGridView .AspNet-GridView table tbody tr td
51.{
52.    cursor:default;
53.    height:20px;
54.    color:#000;
55.    padding:2px 8px;
56.    border-right-style:solid;
57.    border-right-width:1px;
58.    border-right-color:#f2e8da;     
59.    border-bottom-style:solid;
60.    border-bottom-width:1px;    
61.    border-bottom-color:#f2e8da;    
62./*
63.    color: #333333;
64.    background: White;
65.    padding: 2px 20px 2px 2px;
66.    border-bottom: solid 1px #CCCCCC;
67.    border-right: solid 1px #CCCCCC;
68.    text-align: right;
69.*/    
70.}
71.  
72..PrettyGridView .AspNet-GridView table tbody tr.AspNet-GridView-Alternate td
73.{
74.    background: #F7F6F3;
75.}
76.  
77..PrettyGridView .AspNet-GridView table tbody tr.AspNet-GridView-Selected td
78.{
79.}
80.  
81..PrettyGridView .AspNet-GridView table tfoot tr td
82.{
83.}

      7. From Visual Studio, add new class named DataHelper.vb in DNN/App_Code  as shown below

01.Imports Microsoft.VisualBasic
02.Imports System
03.Imports System.Data
04.Imports System.Configuration
05.Imports System.IO
06.Imports System.Web
07.Imports System.Web.Security
08.Imports System.Web.UI
09.Imports System.Web.UI.WebControls
10.Imports System.Web.UI.WebControls.WebParts
11.Imports System.Web.UI.HtmlControls
12.  
13.''' <summary>
14.''' 
15.''' </summary>
16.Public Class GridViewExportUtil
17.  
18.    ''' <summary>
19.    ''' 
20.    ''' </summary>
21.    ''' <param name="fileName"></param>
22.    ''' <param name="gv"></param>
23.    Public Shared Sub Export(ByVal fileName As String, ByVal gv As GridView, ByVal showGrid As Integer)
24.        HttpContext.Current.Response.Clear()
25.        HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", fileName))
26.        HttpContext.Current.Response.ContentType = "application/ms-excel"
27.        Dim sw As StringWriter = New StringWriter
28.        Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
29.        '  Create a form to contain the grid
30.        Dim table As Table = New Table
31.        table.GridLines = showGrid
32.        '  add the header row to the table
33.        If (Not (gv.HeaderRow) Is Nothing) Then
34.            GridViewExportUtil.PrepareControlForExport(gv.HeaderRow)
35.            table.Rows.Add(gv.HeaderRow)
36.        End If
37.        '  add each of the data rows to the table
38.        For Each row As GridViewRow In gv.Rows
39.            GridViewExportUtil.PrepareControlForExport(row)
40.            table.Rows.Add(row)
41.        Next
42.        '  add the footer row to the table
43.        If (Not (gv.FooterRow) Is Nothing) Then
44.            GridViewExportUtil.PrepareControlForExport(gv.FooterRow)
45.            table.Rows.Add(gv.FooterRow)
46.        End If
47.        '  render the table into the htmlwriter
48.        table.RenderControl(htw)
49.        '  render the htmlwriter into the response
50.        HttpContext.Current.Response.Write(sw.ToString)
51.        HttpContext.Current.Response.End()
52.    End Sub
53.  
54.    ''' <summary>
55.    ''' Replace any of the contained controls with literals
56.    ''' </summary>
57.    ''' <param name="control"></param>
58.    Private Shared Sub PrepareControlForExport(ByVal control As Control)
59.        Dim i As Integer = 0
60.        Do While (i < control.Controls.Count)
61.            Dim current As Control = control.Controls(i)
62.            If (TypeOf current Is LinkButton) Then
63.                control.Controls.Remove(current)
64.                control.Controls.AddAt(i, New LiteralControl(CType(current, LinkButton).Text))
65.            ElseIf (TypeOf current Is ImageButton) Then
66.                control.Controls.Remove(current)
67.                control.Controls.AddAt(i, New LiteralControl(CType(current, ImageButton).AlternateText))
68.            ElseIf (TypeOf current Is HyperLink) Then
69.                control.Controls.Remove(current)
70.                control.Controls.AddAt(i, New LiteralControl(CType(current, HyperLink).Text))
71.            ElseIf (TypeOf current Is DropDownList) Then
72.                control.Controls.Remove(current)
73.                control.Controls.AddAt(i, New LiteralControl(CType(current, DropDownList).SelectedItem.Text))
74.            ElseIf (TypeOf current Is CheckBox) Then
75.                control.Controls.Remove(current)
76.                control.Controls.AddAt(i, New LiteralControl(CType(current, CheckBox).Checked))
77.                'TODO: Warning!!!, inline IF is not supported ?
78.            End If
79.            If current.HasControls Then
80.                GridViewExportUtil.PrepareControlForExport(current)
81.            End If
82.            i = (i + 1)
83.        Loop
84.    End Sub
85.  
86.End Class

    8. Replace the content of DNN/DesktopModules/Reports/Visualizers/Grid/Visualizer.ascx with the content as shown below

01.<%@ Control Language="VB" AutoEventWireup="false" Inherits="DotNetNuke.Modules.Reports.Visualizers.Grid.Visualizer" Codebehind="Visualizer.ascx.vb" %>
02.<script runat="server">
03.  
04.    ''' <summary>
05.    ''' 
06.    ''' </summary>
07.    ''' <param name="sender"></param>
08.    ''' <param name="args"></param>
09.    Protected Sub Export2ExcelButton_Click(ByVal sender As Object, ByVal args As EventArgs)
10.        If Me.rdoBtnListExportOptions.SelectedIndex = 1 Then
11.            '  the user wants all rows exported, turn off paging
12.            '  and rebing the grid before sending it to the export
13.            '  utility
14.            Me.grdResults.AllowPaging = False
15.            Me.grdResults.DataBind()
16.        ElseIf Me.rdoBtnListExportOptions.SelectedIndex = 2 Then
17.            '  the user wants just the first 100,
18.            '  adjust the PageSize and rebind
19.            Me.grdResults.PageSize = 100
20.            Me.grdResults.DataBind()
21.        End If
22.  
23.        '  pass the grid that for exporting ...
24.        GridViewExportUtil.Export("Result.xls", Me.grdResults, IIf(Me.chkShowGridLines.Checked, 1, 0))
25.    End Sub
26.  
27.  
28.</script>
29.  
30.<asp:GridView ID="grdResults" runat="server" Width="100%"
31.    EnableTheming="True" AutoGenerateColumns="false" CssSelectorClass="PrettyGridView">
32.<%--
33.    <HeaderStyle CssClass="Subhead DNN_Reports_Grid_Header" HorizontalAlign="Left" />
34.    <RowStyle CssClass="Normal DNN_Reports_Grid_Row" HorizontalAlign="Left" />
35.    <AlternatingRowStyle CssClass="Normal DNN_Reports_Grid_AlternatingRow" />
36.    <PagerStyle CssClass="Normal DNN_Reports_Grid_Pager" HorizontalAlign="Center" />
37.    <FooterStyle CssClass="Normal" />
38.--%>
39.</asp:GridView>
40.<asp:LinkButton ID="Export2ExcelButton" runat="server" Text="Export to Excel"
41.            CssClass="CommandButton" OnClick="Export2ExcelButton_Click" /> 
42.<asp:CheckBox ID="chkShowGridLines" runat="server" /><asp:Label ID="lblShowGridLines" runat="server" Text="Include Grid Lines" />
43.<asp:RadioButtonList ID="rdoBtnListExportOptions" runat="server" RepeatDirection="Horizontal">
44.    <asp:ListItem Value="0" Text="Current Page" />
45.    <asp:ListItem Value="1" Text="All Pages" Selected="True" />
46.    <asp:ListItem Value="2" Text="Top 100 Rows" />
47.</asp:RadioButtonList>

    8. Now, you can preview your report with ASPNET CSS Friendly Adapter and be able to export the grid to Excel. You can modify the PrettyGridView style in DNN/Portals/_default/Default.css for your specific preference.

Hope it help,

Tinboen
 
New Post
6/30/2011 11:25 AM
 
Thanks a lot for posting the scripts above. It really helped me in my project. I don't know why the Excel Export feature was not included into the Reports module from day 1. I mean, Reports and Exports go hand in hand. Your script brought a big wide smile to my face when it enabled Excel Export :-)
 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsReportsReportsUse the ASPNET Css Friendly Adapters 1.0 and Export to ExcelUse the ASPNET Css Friendly Adapters 1.0 and Export to Excel


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out