0

我正在使用导出 PDF 文件

RadGrid1.MasterTableView.ExportToPdf()

这是一个子。我的问题是:我可以以某种方式获取导出的文件路径吗?

先感谢您,

拉霍斯阿尔帕德。

4

1 回答 1

1

导出时,NeedDataSource 事件将触发。将数据存储到一个简单的 ADO.NET 数据表中。

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        DataTable table = new DataTable();
        table.Columns.Add("Col1", typeof(double));
        for (int i = 0; i < 2; i++)
            table.Rows.Add(i);

        (sender as RadGrid).DataSource = table;
    }

自我解释。删除文本框,只留下文本。

public void ReplaceTextBoxes(Control ctrl)
{
    var q = new Stack<Control>(ctrl.Controls.OfType<Control>());
    while (q.Count > 0)
    {
        Control control = q.Pop();
        if (control is ITextControl)
        {
            ctrl.Controls.Add(new LiteralControl((control as ITextControl).Text));
            ctrl.Controls.Remove(control);
        }
        if (control.HasControls())
            ReplaceTextBoxes(control);
    }
}

要存储在服务器上,请添加 OnGridExporting 事件。

protected void RadGrid1_GridExporting(object sender, GridExportingArgs e)
{
    using (FileStream fs = File.Create(Request.PhysicalApplicationPath + "RadGrid.pdf"))
    {
        byte[] output = Encoding.GetEncoding(1252).GetBytes(e.ExportOutput);
        fs.Write(output, 0, output.Length);
    }

    Response.Redirect(Request.Url.ToString());
}

您可以将“RadGrid.pdf”更改为您希望调用的任何名称。

最后是一个按钮来实现这一切(或者你可以在任何地方调用 ExportToPdf 函数。

protected void Button1_Click(object sender, EventArgs e)
{
    foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        ReplaceTextBoxes(item);
    RadGrid1.MasterTableView.ExportToPdf();
}
于 2012-08-10T19:19:07.393 回答