Thursday, January 8, 2009

Adding a control in Report Viewer Toolbar

You can add any asp.net control in report viewer toolbar by using the following code and can writer client side and server side events.


foreach (Control c in ReportViewer1.Controls)
{
if (c.ToString() == "Microsoft.Reporting.WebForms.ToolbarControl")
{
foreach (Control cc in c.Controls)
{
if (cc.ToString() == "Microsoft.Reporting.WebForms.ExportGroup")
{
ImageButton imgButton = new ImageButton();
imgButton.ID = "img1";
imgButton.CausesValidation = false;
imgButton.ImageUrl = "printer_icon.gif";
string targeturl = "http://localhost:1537" + Request.RawUrl.ToString();
imgButton.OnClientClick = "javascript:return OpenNewWindow('" + targeturl + "')";
//OpenNewWindow is a function written in javascript of the page that opens a new window using window.open
imgButton.Click += new ImageClickEventHandler(ImageButton1_Click);
imgButton.ToolTip = "Print";
cc.Controls.Add(imgButton);


}
}
}
}

1 comment:

  1. Do you know of a way to alter the text to say "Print" rather than "Export" I was trying to iterate through the controls but had no luck

    ReplyDelete