Jun
26
Written by:
Dylan Barber
6/26/2009 10:44 AM
We recently deployed a report library for our online application and one of the parameters that exists for almost all reports is what locations to run the report for. Fairly standard huh? So far so great. When we went and looked at how the parameters were presented we were surprised there was no way to adjust the width of those drop down lists, they are hard coded to 184px, this cut off almost half the name of the locations for a lot of our clients, made it very unfriendly to our users.
After some Google searches and a Twitter post basically discovered the only way to really change those is a CSS hack. Thanks to Brandon Hays for his blog post on it located here (Changing the Size of ReportViewer Parameter Dropdown List). Take a look at that blog post for the theory behind this solution. Our problem was that Mr. Hayes stopped a little short of what we needed and so I wanted to share my code so others can benefit from it.
I did this in a DNN module but the basic premise will work for any ASP.NET page that loads reports dynamically into the viewer.
In the page where the report is loaded in the PreRender event you will want to loop through the controls and add the relevant CSS class for the drop down in the report viewer like this:
1: Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
2: For Each oCtrl As Control In Me.ReportViewer1.Controls
3: If oCtrl.GetType.ToString.ToLower = "microsoft.reporting.webforms.parametersarea" Then
4: For Each xCtrl As Control In oCtrl.Controls
5: If xCtrl.GetType.ToString.ToLower = "microsoft.reporting.webforms.multivaluevalidvaluescontrol" Then
6: Me.Literal1.Text += "div#" & xCtrl.ClientID & "_divDropDown {width: 500px !important;}" & vbCrLf
7: End If
8: Next
9: End If
10: Next
11: End Sub
Tags: