English 中文(简体)
Telerik RadGrid Export ToPDF () or Export ToExcel() not working
原标题:Telerik RadGrid ExportToPDF() or ExportToExcel() not working

我有一个简单的类别继承<代码>RadGrid。 我在RadGrid增加一个县,并在该县增加一个Click活动手。 在所需位置上正确地加上了纽伦,点击事件手正在发射,但radGrid.Export ToExcel(<>没有做任何事情。 事实上,当点击时,当页站回头时,纽芬兰就消失了。 为什么发生这种情况?

我试图在<代码>Page.Form的控制收集中增加纽扣控制,但至今没有发生。

[ToolboxData("<{0}:RadGridDp runat=server></{0}:RadGridDp>")]
public class RadGridDP : RadGrid
{
    public RadGridDP()
    {
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        Button btnExport = new Button();
        btnExport.ID = "Export";
        btnExport.Text = "Export";
        btnExport.Click += new EventHandler(btnExport_Click);
        btnExport.CommandArgument = this.ID;
        this.MasterTableView.Controls.Add(btnExport);
    }

    void btnExport_Click(object sender, EventArgs e)
    {
        Button btnExport = (Button)sender;
        string RadGridId = btnExport.CommandArgument.ToString();
        RadGridDP radGrid = (RadGridDP)this.Parent.Parent.FindControl(RadGridId);

        radGrid.ExportSettings.IgnorePaging = true;
        radGrid.ExportSettings.OpenInNewWindow = true;
        radGrid.ExportSettings.ExportOnlyData = true;

        radGrid.MasterTableView.ExportToExcel();
    }
}

当我在<代码>UserControl上做同样的事情,并在任何网页上使用<编码>UserControl时,该编码即行不通。 有什么区别?

最佳回答

I found out the solution. Whenever RadGrid Loads, it calls various events in this fashion:

1. Page OnLoad
m. RadGrid OnLoad
x. NeedDataSource

在被点击纽顿时(以上述方式增加),以这种方式要求事件

1. Page_OnLoad
m. RadGrid OnLoad
n. btnExport_Click
x. NeedDataSource

(as for strange serial numbers, these events may have other events in between, but the order of occurance is correct) so, entire Grid is rebound with the data, and hence command to exportPdf is flushed. So nothing happens. Interestingly, there s no need of adding one extra button, telerik provides its own buttons to do so. which can be customized as well(by implementing ITemplate). This is how am generating Reports now(though not specific to the original question):

    [ToolboxData("<{0}:RadGridDP runat=server></{0}:RadGridDP>")]
    public class RadGridDP : RadGrid
    {
        //custom logic
        public RadGridDP()
        {
            this.ItemCreated += new GridItemEventHandler(RadGrid_ItemCreated);
            this.Load += new EventHandler(RadGridDP_Load);
            this.ItemCommand += new GridCommandEventHandler(RadGrid_ItemCommand);
            this.PdfExporting += new OnGridPdfExportingEventHandler(RadGridDP_PdfExporting);
            this.GridExporting += new OnGridExportingEventHandler(RadGridDP_GridExporting);

            this.ExportSettings.ExportOnlyData = true;
            this.ExportSettings.IgnorePaging = true;
            // this.ExportSettings.OpenInNewWindow = true;

            DoPdfFormatting();
            DoExcelFormatting();

        }
        protected void RadGridDP_PdfExporting(object sender, GridPdfExportingArgs e)
        {
            e.RawHTML = e.RawHTML.Replace("border="1"", "").Replace("style="", "style=" border:0.5px Solid black; ")
                        .Replace("<thead>", String.Format("<thead>{0}", TableHeader)).Replace("</tbody>", String.Format("{0}</tbody>", TableFooter));
        }
        protected void RadGridDP_GridExporting(object sender, GridExportingArgs e)
        {
            e.ExportOutput = e.ExportOutput.Replace("<thead>", String.Format("<thead>{0}", TableHeader))
                             .Replace("</tbody>", String.Format("{0}</tbody>", TableFooter));
        }

  }

so basically i had to handle PdfExporting(for Pdf) and GridExporting(for excel).. I had to handle Load, ItemCommand and ItemCreated as well. While the former one was required for some conditional logic, later two were required for formatting of the PDF document

问题回答

暂无回答




相关问题
Discuss on Commercial Component libraries of silverlight

I am now looking forward to buy a component library of silverlight for increase the productivity. I find there are number of them. Telerik ComponentOne ComponentArt Infragistics Syncfusion I found ...

Telerik RadGrid: grid clientside pagination

I have a web service which returns me some data,I am massaging this data and using this as datasource for my radgrid (telerik). The datasource is quite large, and would like to paginate it. I found ...

Binding a radgrid to a tree like data structure

I have a structure that looks following Class TreeNode { public TreeNode Parent { get; } public IEnumerable<TreeNode> Children { get; } public . . . . } I want to bind this to a ...

IQueryable into a hierarchy

I currently have an IQueryable of Questions. In my Question object I have and "id" and a "parentId" which can be used to create a hierarchy. Currently, I bind a RadTreeView to the IQueryable of ...

Expand all items in RadGrid Hierarchy

I am using a RadGrid (2009 Q2) with a hierarchy. Is there a way in the client api to expand all rows and vice-versa? thanks! Update: I have written a javascript function based off the api ...

热门标签