gpt4 book ai didi

sharepoint - 将多个参数从自定义 WebPart 传递到 Reporting Services 报表查看器 Web 部件

转载 作者:行者123 更新时间:2023-12-04 00:01:41 26 4
gpt4 key购买 nike

我在 Sharepoint 模式下使用报告服务,我能够在 Sql Server 报告服务报告查看器中显示报告,报告有多个参数,我的问题是如何将多个参数从自定义 Web 部件传递到此报告。

我可以通过在自定义 webpart 中实现 ITransformableFilterValues 接口(interface)来传递一个参数,我想要做的是传递多个参数。

例如:如果报告上有 2 个参数,那么我应该能够从 webpart 中的控件映射每个参数。

最佳答案

这是自定义 Webpart 的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using aspnetwebparts = System.Web.UI.WebControls.WebParts;
//using Microsoft.Office.Server.Utilities;
using wsswebparts = Microsoft.SharePoint.WebPartPages;
//using Microsoft.SharePoint.Portal.WebControls;
using System.Collections.ObjectModel;
using Microsoft.SharePoint.Utilities;
using System.Data;
using System.Collections;

namespace CustomWebPart
{
/// <summary>
/// Used to provide filter values for the status report.
/// </summary>
public class StatusReportFiler : aspnetwebparts.WebPart, wsswebparts.ITransformableFilterValues
{
DropDownList ddlCategory;
ListItem lstItem;
Label lblCaption;

public virtual bool AllowMultipleValues
{
get
{
return false;
}
}
public virtual bool AllowAllValue
{
get
{
return true;
}
}

public virtual bool AllowEmptyValue
{
get
{
return false;
}
}
public virtual string ParameterName
{
get
{
return "Category";
}
}



public virtual ReadOnlyCollection<string> ParameterValues
{
get
{
string[] values = this.GetCurrentlySelectedCategory();
return values == null ?
null :
new ReadOnlyCollection<string>(values);
}
}


protected override void CreateChildControls()
{


lblCaption = new Label();
lblCaption.Text = "&nbsp; Category:&nbsp;";

Controls.Add(lblCaption);

ddlCategory = new DropDownList();
ddlCategory.AutoPostBack = true;

lstItem = new ListItem();
lstItem.Text = "Select All Category";
lstItem.Value = "0";
ddlCategory.Items.Add(lstItem);
lstItem = null;


lstItem = new ListItem();
lstItem.Text = "BING";
lstItem.Value = "Bing";
ddlCategory.Items.Add(lstItem);
lstItem = null;

lstItem = new ListItem();
lstItem.Text = "Google";
lstItem.Value = "Google";
ddlCategory.Items.Add(lstItem);
lstItem = null;


Controls.Add(ddlCategory);



// base.CreateChildControls();
}


[aspnetwebparts.ConnectionProvider("Category Filter", "ITransformableFilterValues", AllowsMultipleConnections = true)]
public wsswebparts.ITransformableFilterValues SetConnectionInterface()
{
return this;
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
}

public string[] GetCurrentlySelectedCategory()
{
string[] selCategory = new string[1];
selCategory[0] = ddlCategory.SelectedValue;
return selCategory;
}

protected override void RenderContents(HtmlTextWriter htmlWriter)
{


/*htmlWriter.Write("<table border=\"0\" width=\"100%\">");
htmlWriter.Write("<tr><td>");
lblCaption.RenderControl(htmlWriter);
htmlWriter.Write("</td></tr>");
htmlWriter.Write("<tr><td>");
lblCaption.RenderControl(htmlWriter);
htmlWriter.Write("</td></tr>");
htmlWriter.Write("</table>");*/

this.EnsureChildControls();
RenderChildren(htmlWriter);

}

}
}
  • 构建此 Webpart 后,将其部署到 SharePoint。
    在 Sharpoint 中创建一个 Webpart 页面,将自定义 Web 部件添加到页面中。
    添加后,您将能够在 Webpart 上看到带有值的下拉列表。
  • 在另一个 Add Webpart 部分中添加一个 Sql Server Reporting Sevices ReportViewer web 部件并在属性部分中设置报告 URL 并单击 apply ,此报告应具有与自定义 Webpart 中相同的参数名称。
  • 在自定义 Webpart 中,单击编辑 -> 连接 -> 将类别过滤器发送到 -> ReportViewer - AAAA(这是我猜的 ReportName)。这将弹出一个带有映射部分的窗口,将 Filer Category 映射到 Report 上的 Filtered 参数,然后单击 Finish。这会将值从 Webpart 传递到 Report。

  • 希望这可以帮助。

    关于sharepoint - 将多个参数从自定义 WebPart 传递到 Reporting Services 报表查看器 Web 部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2564178/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com