8a9918d0cb20ff05c5e8c99b8a6faa89eabd7368
API/CodeSamples/ReportViewer/Custom-Export-Buttons.md
| ... | ... | @@ -9,4 +9,90 @@ This code sample will allow you to place your own export buttons wherever you ne |
| 9 | 9 | ```csharp |
| 10 | 10 | <img src="rs.aspx?image=pdf.gif" onclick="window.location='<%=string.Format("{0}? |
| 11 | 11 | {1}&output=pdf",Request.ServerVariables["PATH_INFO"],Request.ServerVariables"QUERY_STRING"])%>'" |
| 12 | +``` |
|
| 13 | + |
|
| 14 | +##C♯ Sample |
|
| 15 | + |
|
| 16 | +This code sample will allow you to use the Izenda API to generate custom export capabilities with a standard webforms page. |
|
| 17 | + |
|
| 18 | +```csharp |
|
| 19 | +using System; |
|
| 20 | +using System.Data; |
|
| 21 | +using System.Configuration; |
|
| 22 | +using System.Collections; |
|
| 23 | +using System.Web; |
|
| 24 | +using System.Web.Security; |
|
| 25 | +using System.Web.UI; |
|
| 26 | +using System.Web.UI.WebControls; |
|
| 27 | +using System.Web.UI.WebControls.WebParts; |
|
| 28 | +using System.Web.UI.HtmlControls; |
|
| 29 | +using Izenda.AdHoc; |
|
| 30 | +using Izenda.AdHoc.Database; |
|
| 31 | + |
|
| 32 | +public partial class Export : System.Web.UI.Page |
|
| 33 | +{ |
|
| 34 | + protected void Page_Load(object sender, EventArgs e) |
|
| 35 | + { |
|
| 36 | + foreach(string ds in AdHocContext.Driver.DatabaseSchema.Tables.AllKeys) |
|
| 37 | + { |
|
| 38 | + DataSourcesDD.Items.Add(ds); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + protected void DSButton_Click(object sender, EventArgs e) |
|
| 43 | + { |
|
| 44 | + foreach (Column column in AdHocContext.Driver.DatabaseSchema.Tables |
|
| 45 | + [DataSourcesDD.SelectedItem.Value].Columns.AllValues) |
|
| 46 | + { |
|
| 47 | + ListItem li = new ListItem(); |
|
| 48 | + li.Text = column.Name; |
|
| 49 | + li.Value = column.SqlName; |
|
| 50 | + li.Selected = true; |
|
| 51 | + FieldCBL.Items.Add(li); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + protected void ExportButton_Click(object sender, EventArgs e) |
|
| 56 | + { |
|
| 57 | + ReportSet rs = new ReportSet(); |
|
| 58 | + |
|
| 59 | + JoinedTable jt = new JoinedTable(); |
|
| 60 | + jt.TableName = DataSourcesDD.SelectedItem.Value; |
|
| 61 | + rs.JoinedTables.Add(jt); |
|
| 62 | + |
|
| 63 | + foreach (ListItem li in FieldCBL.Items) |
|
| 64 | + { |
|
| 65 | + if (!li.Selected) continue; |
|
| 66 | + |
|
| 67 | + Field f = new Field(li.Value); |
|
| 68 | + rs.Detail.Fields.Add(f); |
|
| 69 | + } |
|
| 70 | + AdHocContext.CurrentReportSet = rs; |
|
| 71 | + Response.Redirect("rs.aspx?output=csv"); |
|
| 72 | + } |
|
| 73 | +} |
|
| 74 | +``` |
|
| 75 | + |
|
| 76 | +```html |
|
| 77 | +<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Default.master" CodeFile="Export.aspx.cs" Inherits="Export" %> |
|
| 78 | + |
|
| 79 | +<asp:Content ID="Content1" ContentPlaceHolderID="HeadPlaceHolder" runat="Server"> |
|
| 80 | +</asp:Content> |
|
| 81 | +<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolder" runat="Server"> |
|
| 82 | + <div class="page"> |
|
| 83 | + <form id="form1" runat="server"> |
|
| 84 | + <div> |
|
| 85 | + <asp:DropDownList ID="DataSourcesDD" runat="server"> |
|
| 86 | + </asp:DropDownList> |
|
| 87 | + <asp:Button ID="DSButton" runat="server" Text="OK" OnClick="DSButton_Click" /> |
|
| 88 | + <asp:CheckBoxList ID="FieldCBL" runat="server" RepeatColumns="5"> |
|
| 89 | + </asp:CheckBoxList> |
|
| 90 | + </div> |
|
| 91 | + <asp:Button ID="ExportButton" runat="server" Text="Export" OnClick="ExportButton_Click" /> |
|
| 92 | + </form> |
|
| 93 | + </div> |
|
| 94 | +</asp:Content> |
|
| 95 | + |
|
| 96 | +<asp:Content ID="Content3" ContentPlaceHolderID="TrackerPlaceHolder" runat="Server"> |
|
| 97 | +</asp:Content> |
|
| 12 | 98 | ``` |
| ... | ... | \ No newline at end of file |