in

CodeSmith Community

Your Code. Your Way. Faster!

EntityGridView Export to Excel add option to include hidden columns

Last post 06-29-2007 8:02 AM by clstopher. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 05-18-2007 9:16 AM

    • millerwa
    • Top 500 Contributor
    • Joined on 05-03-2007
    • Posts 18
    • Points 465

    EntityGridView Export to Excel add option to include hidden columns

    Would it be possible to add an option to include hidden columns for export? This would be handy so when showing only a limited number of columns on the screen just to reduce UI clutter.

     

    • Post Points: 35
  • 05-21-2007 12:17 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 723
    • Points 16,775

    Re: EntityGridView Export to Excel add option to include hidden columns

    millerwa,

    Good suggestion. The support for that has been added (rev. 564)

    <data:EntityGridView ID="GridView1" runat="server"   
      AutoGenerateColumns="False"     
      DataSourceID="CategoriesDataSource"
      DataKeyNames="CategoryID"
      AllowMultiColumnSorting="false"
      DefaultSortColumnName=""
      DefaultSortDirection="Ascending" 
      ExcelExportFileName="Export_Categories.xls"   
     >
     <ExcelColumns>
         <asp:BoundField DataField="Description" HeaderText="Description"  />
     </ExcelColumns>

     <Columns>
      <asp:CommandField ShowSelectButton="True" ShowEditButton="True" />    
      <asp:BoundField DataField="CategoryName" HeaderText="Category Name" SortExpression="CategoryName"  />  
      <asp:BoundField DataField="Picture" HeaderText="Picture" SortExpression="Picture"  />
     </Columns>
     <EmptyDataTemplate>
      <b>No Categories Found!</b>
     </EmptyDataTemplate>
    </data:EntityGridView>

    There are also two new events were added, ExcelBeforeFormat and ExcelAfterFormat, that could be used to tap into formatting function of the control.

        GridView1.ExcelBeforeFormat += new ExcelFormatEventHandler(GridView1_ExcelBeforeFormat);

        void GridView1_ExcelBeforeFormat(object sender, ExcelFormatEventArgs e)
        {
            if (e.Control is HyperLink && e.ColumnName == "Ship Via")
            {
                HyperLink h = (HyperLink)e.Control;
                if (h.Text.Length > 5 && h.Text != "Speedy Express")
                    h.Text = string.Format("{0} ...", h.Text.Substring(1, 4));
                else
                    e.Cancel = true;
            }
        }

    Mike Shatny
    -------------------------------------
    Member of the .netTiers team
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 65
  • 06-01-2007 8:48 AM In reply to

    • Cathy-ki
    • Top 500 Contributor
    • Joined on 06-01-2007
    • Posts 10
    • Points 260

    Re: EntityGridView Export to Excel add option to include hidden columns

    Hi,

    I am a new user of nettiers too and I would like to ask you how can I use the above code because I have the latest (I think) version of nettiers but <ExcelColumns> is not recognized and allowed to use.

    Thanks 

     

     

    • Post Points: 35
  • 06-01-2007 9:38 AM In reply to

    • millerwa
    • Top 500 Contributor
    • Joined on 05-03-2007
    • Posts 18
    • Points 465

    Re: EntityGridView Export to Excel add option to include hidden columns

    I'm not exactly sure when they create a release so you will probably need to use somthing like Tortise to get the lastest build, I do have the latest and it does offer the ExcelColumns feature.

    There are some posts out there on how to get the latest, but here are some simple steps:

    1) download and install Tortise

    2) Create a new folder on your desktop

    3) right click you should see the SVN Checkout for the Url I think you use https://svn.sourceforge.net/svnroot/nettiers/

    4) Wait... Eventually it will get everything and you should have the latest.

    5) Regenerate using this latest template and you should be good to go.

    • Post Points: 5
  • 06-28-2007 10:07 AM In reply to

    • clstopher
    • Not Ranked
    • Joined on 06-28-2007
    • Posts 3
    • Points 75

    Re: EntityGridView Export to Excel add option to include hidden columns

    Mike,

    I really like the new export columns feature of the EntityGridView, however, one thing I've found is that I actually don't want to include the columns that are in the original GridView; I think it is easier to configure the two types of output if they are handled completely separately.  I looked at the code, and it was a pretty simple change (one-liner).  I think this functionality may be useful to other people so I figured I'd send you back my change and see if you wanted to include it in the actual code.

     So the new behavior (after this patch) is that the "Columns" property is displayed on the page, and the "ExcelColumns" property is displayed on the export, if you want a column in both, you have to list it in both.

     I don't see a way to attach a file, so I'm just going to paste the patch file in here; Sorry if I'm just missing it :)

     Index: Source/WebLibrary/UI/EntityGridView.cs.cst
    ===================================================================
    --- Source/WebLibrary/UI/EntityGridView.cs.cst (revision 583)
    +++ Source/WebLibrary/UI/EntityGridView.cs.cst (working copy)
    @@ -554,6 +554,7 @@
             {
                 if (ExcelColumns != null)
                 {
    +                this.Columns.Clear();
                     foreach (DataControlField field in ExcelColumns)
                     {
                         this.Columns.Add(field);

    • Post Points: 35
  • 06-28-2007 7:47 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 723
    • Points 16,775

    Re: EntityGridView Export to Excel add option to include hidden columns

    clstopher,

    I see what you say - valid point. What if we add a property something like ExportAllColumns, which would be used to decide include all the columns or only ExcelColumns?

     

    Mike Shatny
    -------------------------------------
    Member of the .netTiers team
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 35
  • 06-29-2007 8:02 AM In reply to

    • clstopher
    • Not Ranked
    • Joined on 06-28-2007
    • Posts 3
    • Points 75

    Re: EntityGridView Export to Excel add option to include hidden columns

    I had considered adding it as an option, but I figured it's just adding more complexity to the code that really isn't necessary; Obviously if you'd rather have an option, that works for me too, but I think semantically it makes more sense to have the two column sets work as entirely separate sets.  If you'd rather I implement it as an option, let me know and I'll add an option.  I haven't used NetTiers very much yet though, so let me know what you'd like the option name to be to stay consistent with other options.  Also - I'm leaving for vacation, so I'll do it after the 4th.

     

    Chris 

    • Post Points: 5
Page 1 of 1 (7 items)
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems