在ReportViewer中使用超链接(HyperLink)

今天,需要在ReportViewer报表上链接到别一个页面上。
于是给TextBox加上一个Action,并在Action内指定HyperLink,
结果发现,如果指定给HyperLink的不是绝对URL,它就不起作用。
但开发的时候不可能就指出绝对的URL。

而要取得客户端访问的绝对的URL也不是一样容易的事:-),

经过测试,发现只有Request.Url提供此信息。
于是可以采用下方法来指定绝对URL。
1. 在Report上增加报表参数Current_Virtual_Path。

2. 写ReportViewer的Load事件:代码如下:

 1         string req_url = this.Request.Url.ToString();
 2 
 3         int pos = req_url.LastIndexOf('/');
 4 
 5         if (pos > 0)
 6         {
 7             string current_virtual_path = req_url.Substring(0, pos + 1);
 8             ReportViewer1.LocalReport.SetParameters(new ReportParameter[] {
 9             new ReportParameter("current_virtual_path", current_virtual_path) });
10         }

也就是在报表Load的时候把该URL的目录信息作为报表参数传递给Reportviewer。

3. 指定HyperLink的标签的内容为:
=Parameters!current_virtual_path.Value + "文件.aspx"

4. 修改ReportViewer.LocalReport.EnableHyperLinks 为true。

至此搞定。

posted on 2006-10-11 17:38  bela liu  阅读(2410)  评论(1编辑  收藏  举报

导航