7

有什么方法可以在 Microsoft.Reporting.WebForms.ReportViewer 控件中添加我的自定义控件。
我正在开发 ASP.NET Web 应用程序,我想在 reportviewer 的工具栏中添加我的自定义控件。

阅读这个blogspot看起来这在 WinForms 中是可能的。

因此,我开始编写我自己的继承 ReportViewer 的 RerpotViewerClass 并在开始时堆叠起来。看起来我不能覆盖 WebForms 上的 OnControlAdded 方法?
然后我使用 OnLoad() 或任何其他方法?

   public class ReportViewerToolbarExtension : Microsoft.Reporting.WebForms.ReportViewer
    {
        protected override void OnControlAdded(ControlEventArgs e)
        {

                base.OnControlAdded(e);

        }        
    }

引发错误

'Microsoft.Reporting.WebForms.ReportViewer' does not contain a definition for 'OnControlAdded'  

“ControlEventArgs”对我来说也是痛苦的一部分吗?

当我尝试实现 SetToolStripItems(Control c)

我不能使用 ToolStripItemCollection 也工具条,因为它们属于命名空间 System.Windows.Forms。
我应该引用 WinForms 还是 Web 命名空间中有模拟控件?

4

2 回答 2

9

遗憾的是,无法自定义 Web 报表查看器工具栏。通过查看反汇编代码可以看到使用的 ToolbarControl 是自定义的,它是一个内部密封类,您只能隐藏或显示工具栏。

但是,您可以隐藏工具栏并创建自己的工具栏,以实现与现有工具栏和您自己的控件相同的功能。

这是微软建议的路线。

如果您想要不同的工具栏实现,您可以创建自定义工具栏来替换默认工具栏。

这可以在以下位置找到:http: //msdn.microsoft.com/en-us/library/ms251670.aspx

我要做的是反汇编代码并将其重新实现为具有所有子类的公共类,从我的第一眼看来,这些子类似乎没有什么太复杂或难以做的事情。

也可以通过使用jquery之类的工具或仅DOM api编辑 DOM 来通过前端添加它。下面的 Web 开发人员帖子演示了如何做到这一点。记住,如果您希望将服务器端控件添加到工具栏中,则需要确保您不会使视图状态无效并且它们可以正常工作。

有关类似问题,请参阅 asp.net 论坛上托管的以下帖子。

有用的拆卸工具。

希望这可以帮助

于 2013-03-09T15:57:33.250 回答
4

在此处输入图像描述

默认.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    <asp:ScriptManager runat="server" EnablePartialRendering="false">
    </asp:ScriptManager>
    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="830px" Font-Names="Verdana" Font-Size="8pt" InteractiveDeviceInfos="(Коллекция)" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
        <LocalReport ReportPath="Report.rdlc">
        </LocalReport>
    </rsweb:ReportViewer>
    <div id="container" class=" " style="display: inline-block; font-family: Verdana; font-size: 8pt; vertical-align: top;">
        <table cellpadding="0" cellspacing="0" style="display: inline;">
            <tbody>
                <tr>
                    <td height="28px">
                        <asp:DropDownList runat="server" ID="ComboBox1" OnSelectedIndexChanged="ComboBox1_SelectedIndexChanged" AutoPostBack="True">
                            <asp:ListItem>Option 1</asp:ListItem>
                            <asp:ListItem>Option 2</asp:ListItem>
                            <asp:ListItem>Option 3</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $($('#ReportViewer1_fixedTable').find('td[colspan=3] div[id^="ReportViewer1"]')[1])
                    .find('div')
                    .first()
                    .append($('#container').detach());
        });
    </script>
    </form>
</body>
</html>

默认.aspx.cs

using System;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = ComboBox1.SelectedItem.Text;
    }
}

当您使用 ExtJS 或 Ext.Net 时,请将脚本块替换为:

<script type="text/javascript">
    Ext.onReady(function () {
        Ext.get(Ext.query('#ReportViewer1 td[colspan=3] div[id^="ReportViewer1"]')[1]).last().appendChild(Ext.get(Ext.query('#container')));
    });
</script>
于 2013-03-14T14:29:14.077 回答