<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Raj Kaimal  : Data</title><link>http://weblogs.asp.net/rajbk/archive/tags/Data/default.aspx</link><description>Tags: Data</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Rendering an RDLC directly to the Response stream in ASP.NET MVC</title><link>http://weblogs.asp.net/rajbk/archive/2009/11/25/rendering-an-rdlc-directly-to-the-response-stream-in-asp-net-mvc.aspx</link><pubDate>Wed, 25 Nov 2009 07:21:59 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7264611</guid><dc:creator>rajbk</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/rajbk/rsscomments.aspx?PostID=7264611</wfw:commentRss><comments>http://weblogs.asp.net/rajbk/archive/2009/11/25/rendering-an-rdlc-directly-to-the-response-stream-in-asp-net-mvc.aspx#comments</comments><description>&lt;p&gt;The following post shows you how to render an &lt;a href="http://msdn.microsoft.com/en-us/library/ms252067.aspx" target="_blank"&gt;RDLC&lt;/a&gt; (Client Report Definition File) in a MVC project. For this tutorial, I am using VS 2008 with &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=4817cdb2-88ea-4af4-a455-f06b4c90fd2c&amp;amp;displaylang=en" target="_blank"&gt;MVC 2 Beta&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;. I will also be using the priceless Northwind database and the report will contain a list of customers in the Northwind database.     &lt;br /&gt;    &lt;br /&gt;A sample project zip file is provided at the bottom of this post.     &lt;br /&gt;    &lt;br /&gt;We start off by creating an ASP.NET MVC 2 Empty Web Application.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_7A859418.png" width="634" height="379" /&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Add a new ADO.NET entity model and choose the option to “Generate from the database”.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_390AE1BF.png" width="634" height="349" /&gt;     &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_3BD096B2.png" width="627" height="305" /&gt;&amp;#160; &lt;br /&gt;Choose the connection string to use&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_28AF6A06.png" width="627" height="435" /&gt;&lt;/p&gt;  &lt;p&gt;Choose the database objects (Customers for our scenario) and hit finish. We see that a new entity data model has been created in the Models directory.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_4066A16C.png" width="627" height="558" /&gt;&amp;#160; &lt;br /&gt;Create a folder called Content and a subfolder called Reports and add an RDLC into this folder. I hate working with Datasets and hence will not be using the “Report Wizard”. We choose the “Report” template instead.&amp;#160; &lt;br /&gt;    &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_1E9AC8DB.png" width="634" height="488" /&gt; &lt;/p&gt;  &lt;p&gt;Create a method that returns all the customers in the database through a Customer partial class and add this in the Model folder.    &lt;br /&gt;    &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_36520041.png" width="229" height="84" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; RDLCRendering.Models&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Customers&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; List&amp;lt;Customers&amp;gt; GetAllCustomers() {&lt;br /&gt;            var entities = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; NorthwindEntities();&lt;br /&gt;            var x = from c &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; entities.Customers&lt;br /&gt;                    select c;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; x.ToList();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;Open&amp;#160; the RDLC. Your UI should look like so (If you don’t see “Website Data Sources”, click on Data –&amp;gt; Show Data Sources):&lt;/div&gt;

&lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_63D32004.png" width="647" height="441" /&gt; &lt;/p&gt;

&lt;p&gt;Design your report by adding a table from the toolbox and dragging and dropping fields from the Website Data Sources (&lt;a href="http://msdn.microsoft.com/en-us/library/ms251659(VS.80).aspx" target="_blank"&gt;reference&lt;/a&gt;). &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_54500E35.png" width="673" height="290" /&gt;&amp;#160; &lt;/p&gt;

&lt;p&gt;We will now construct our basic MVC web application. The app will have a home screen and a link to view the PDF report of Northwind customers. 
  &lt;br /&gt;Lets start by adding a Home controller&lt;/p&gt;

&lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_484E1E01.png" width="497" height="204" /&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;We add the following code in our HomeController class&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; RDLCRendering.Controllers&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; HomeController : Controller&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult Index()&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; welcomeMessage = &lt;span style="color: #006080"&gt;&amp;quot;Welcome to Northwind Traders. Enjoy the view!&amp;quot;&lt;/span&gt;;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; View((&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;)welcomeMessage);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;
  &lt;br /&gt;Right click on the &amp;quot;Index()” method and select “Add View”.&lt;/div&gt;

&lt;div&gt;
  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rajbk/image_1988655F.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_thumb_0D86752B.png" width="447" height="441" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Open the Index view and add code to display the string returned and also add a link for the report in the view like so:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&amp;lt;%@ Page Language=&lt;span style="color: #006080"&gt;&amp;quot;C#&amp;quot;&lt;/span&gt; Inherits=&lt;span style="color: #006080"&gt;&amp;quot;System.Web.Mvc.ViewPage&amp;lt;string&amp;gt;&amp;quot;&lt;/span&gt; %&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC &lt;span style="color: #006080"&gt;&amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #006080"&gt;&amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;&amp;lt;html xmlns=&lt;span style="color: #006080"&gt;&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;&amp;lt;head runat=&lt;span style="color: #006080"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;    &amp;lt;title&amp;gt;Index&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;    &amp;lt;div&amp;gt;&lt;br /&gt;        &lt;font color="#ff0000"&gt;&amp;lt;h2&amp;gt;&lt;br /&gt;            &amp;lt;%=Html.Encode(Model) %&amp;gt;&amp;lt;/h2&amp;gt;&lt;/font&gt;&lt;br /&gt;            &lt;br /&gt;           &lt;font color="#ff0000"&gt; &amp;lt;%=Html.ActionLink(&lt;span style="color: #006080"&gt;&amp;quot;Customers Report (PDF)&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;DetailsReport&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;Customers&amp;quot;&lt;/span&gt;) %&amp;gt;&lt;br /&gt;&lt;/font&gt;    &amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Run the application. You should see a UI similar to the one below:&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_4C77F5C6.png" width="575" height="240" /&gt; 

  &lt;br /&gt;If you click on the link you will get a “The resource cannot be found.” error. This is because our Html.Action link refers to a method called “DetailsReport” in a CustomersController which does not exist yet. 

  &lt;br /&gt;&lt;font size="1"&gt;Note that we are using the ActionLink overload(linkText, actionName, controllerName).&lt;/font&gt; &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;First add a reference to Microsoft.ReportViewer.WebForms in your project.&lt;/div&gt;

&lt;div&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_0B697662.png" width="304" height="109" /&gt; &lt;/div&gt;

&lt;div&gt;Add a CustomerController class and add a DetailsReport method like so: 
  &lt;br /&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Web;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Web.Mvc;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Web.Mvc.Ajax;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.Reporting.WebForms;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; RDLCRendering.Models;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; RDLCRendering.Controllers&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CustomersController : Controller&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult Index()&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; View();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult DetailsReport()&lt;br /&gt;        {&lt;br /&gt;            LocalReport localReport = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; LocalReport();&lt;br /&gt;            localReport.ReportPath = Server.MapPath(&lt;span style="color: #006080"&gt;&amp;quot;~/Content/Reports/CustomerReport.rdlc&amp;quot;&lt;/span&gt;);&lt;br /&gt;            ReportDataSource reportDataSource = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ReportDataSource(&lt;span style="color: #006080"&gt;&amp;quot;Customers&amp;quot;&lt;/span&gt;, Customers.GetAllCustomers());&lt;br /&gt;&lt;br /&gt;            localReport.DataSources.Add(reportDataSource);&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; reportType = &lt;span style="color: #006080"&gt;&amp;quot;PDF&amp;quot;&lt;/span&gt;;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; mimeType;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; encoding;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fileNameExtension;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #008000"&gt;//The DeviceInfo settings should be changed based on the reportType&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #008000"&gt;//http://msdn2.microsoft.com/en-us/library/ms155397.aspx&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; deviceInfo =&lt;br /&gt;            &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;DeviceInfo&amp;gt;&amp;quot;&lt;/span&gt; +&lt;br /&gt;            &lt;span style="color: #006080"&gt;&amp;quot;  &amp;lt;OutputFormat&amp;gt;PDF&amp;lt;/OutputFormat&amp;gt;&amp;quot;&lt;/span&gt; +&lt;br /&gt;            &lt;span style="color: #006080"&gt;&amp;quot;  &amp;lt;PageWidth&amp;gt;8.5in&amp;lt;/PageWidth&amp;gt;&amp;quot;&lt;/span&gt; +&lt;br /&gt;            &lt;span style="color: #006080"&gt;&amp;quot;  &amp;lt;PageHeight&amp;gt;11in&amp;lt;/PageHeight&amp;gt;&amp;quot;&lt;/span&gt; +&lt;br /&gt;            &lt;span style="color: #006080"&gt;&amp;quot;  &amp;lt;MarginTop&amp;gt;0.5in&amp;lt;/MarginTop&amp;gt;&amp;quot;&lt;/span&gt; +&lt;br /&gt;            &lt;span style="color: #006080"&gt;&amp;quot;  &amp;lt;MarginLeft&amp;gt;1in&amp;lt;/MarginLeft&amp;gt;&amp;quot;&lt;/span&gt; +&lt;br /&gt;            &lt;span style="color: #006080"&gt;&amp;quot;  &amp;lt;MarginRight&amp;gt;1in&amp;lt;/MarginRight&amp;gt;&amp;quot;&lt;/span&gt; +&lt;br /&gt;            &lt;span style="color: #006080"&gt;&amp;quot;  &amp;lt;MarginBottom&amp;gt;0.5in&amp;lt;/MarginBottom&amp;gt;&amp;quot;&lt;/span&gt; +&lt;br /&gt;            &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/DeviceInfo&amp;gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;            Warning[] warnings;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] streams;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] renderedBytes;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #008000"&gt;//Render the report&lt;/span&gt;&lt;br /&gt;            renderedBytes = localReport.Render(&lt;br /&gt;                reportType,&lt;br /&gt;                deviceInfo,&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; mimeType,&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; encoding,&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; fileNameExtension,&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; streams,&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; warnings);&lt;br /&gt;            &lt;span style="color: #008000"&gt;//Response.AddHeader(&amp;quot;content-disposition&amp;quot;, &amp;quot;attachment; filename=NorthWindCustomers.&amp;quot; + fileNameExtension);&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; File(renderedBytes, mimeType);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;This method will create an instance of the LocalReport class, set the Report path property, add a ReportDataSource which points to the GetAllCustomers method we defined earlier, set the report output type and page dimensions, calls the render method and invokes the File method on the Controller class. This method return a &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.filecontentresult.aspx" target="_blank"&gt;FileContentResult&lt;/a&gt; which sends the contents of a binary file to the response stream. 

  &lt;br /&gt;&lt;/div&gt;

&lt;div&gt;Run the page and click on the link. You should see the PDF report like so:&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rajbk/image_6EEC8481.png" width="938" height="365" /&gt; &lt;/div&gt;

&lt;div&gt;&lt;strong&gt;If you wish to prompt the user to download the PDF file, uncomment the “content-disposition” line and recompile.&lt;/strong&gt; 

  &lt;br /&gt;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;&amp;#160; &lt;br /&gt;&lt;/div&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:2491eac2-cad1-4576-9281-da659a8c1205" class="wlWriterEditableSmartContent"&gt;&lt;div&gt;&lt;a href="http://weblogs.asp.net/blogs/rajbk/RDLCRendering_3BB04B18.zip" target="_blank"&gt;Download Sample MVC Beta 2 project&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div&gt;
  &lt;br /&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7264611" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rajbk/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/rajbk/archive/tags/Data/default.aspx">Data</category><category domain="http://weblogs.asp.net/rajbk/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/rajbk/archive/tags/ADO.NET/default.aspx">ADO.NET</category><category domain="http://weblogs.asp.net/rajbk/archive/tags/MVC/default.aspx">MVC</category></item><item><title>SQL 2005 - Maximum number of characters displayed in each column</title><link>http://weblogs.asp.net/rajbk/archive/2007/09/27/sql-2005-maximum-number-of-characters-displayed-in-each-column.aspx</link><pubDate>Thu, 27 Sep 2007 17:52:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:4216434</guid><dc:creator>rajbk</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/rajbk/rsscomments.aspx?PostID=4216434</wfw:commentRss><comments>http://weblogs.asp.net/rajbk/archive/2007/09/27/sql-2005-maximum-number-of-characters-displayed-in-each-column.aspx#comments</comments><description>&lt;p mce_keep="true"&gt;This setting in Microsoft SQL server management studio, which has a default setting of 256 characters,&amp;nbsp;caused me to waste almost half an hour yesterday. I was looking in the wrong places trying to troubleshoot my stored procedure and wondering why my data was being truncated. There is no indication in management studio that the&amp;nbsp;text was being truncated either.&lt;/p&gt;
&lt;p mce_keep="true"&gt;To increase the maximum value, open SQL Server management studio and go to &lt;/p&gt;
&lt;p mce_keep="true"&gt;&amp;nbsp;Tools » Options » Query Results » Results to Text » Maximum number of characters displayed in each column&lt;/p&gt;
&lt;p mce_keep="true"&gt;Note also that there is a "Maximum Characters Retrieved" section under "Results to Grid" section too.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4216434" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rajbk/archive/tags/Data/default.aspx">Data</category><category domain="http://weblogs.asp.net/rajbk/archive/tags/SQL/default.aspx">SQL</category></item><item><title>Changing the connectionstring of a wizard generated TableAdapter at runtime from an ObjectDataSource</title><link>http://weblogs.asp.net/rajbk/archive/2007/05/26/changing-the-connectionstring-of-a-wizard-generated-tableadapter-at-runtime-from-an-objectdatasource.aspx</link><pubDate>Sat, 26 May 2007 16:41:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2662487</guid><dc:creator>rajbk</dc:creator><slash:comments>25</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/rajbk/rsscomments.aspx?PostID=2662487</wfw:commentRss><comments>http://weblogs.asp.net/rajbk/archive/2007/05/26/changing-the-connectionstring-of-a-wizard-generated-tableadapter-at-runtime-from-an-objectdatasource.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;The&amp;nbsp;Visual Studio 2005 Dataset designer allows you to create a DAL using a typed dataset and easily bind this to a GridView with the help of an ObjectDataSource. By default, in the TableAdapter generated, the visibility of the encapsulated Connection object is set to private. &lt;/P&gt;
&lt;P mce_keep="true"&gt;For the calling code to specify its own Connection object,&amp;nbsp;the visibility of the Connection property has to be made public. This can be done&amp;nbsp;by setting the &lt;STRONG&gt;ConnectionModifier&lt;/STRONG&gt; property of the TableAdapter to public. &lt;BR&gt;&lt;BR&gt;&lt;IMG title=ConnectionModifier style="WIDTH: 444px; HEIGHT: 340px" height=340 alt=ConnectionModifier src="http://weblogs.asp.net/rajbk/attachment/2662487.ashx" width=444 mce_src="http://weblogs.asp.net/rajbk/attachment/2662487.ashx"&gt;&lt;BR&gt;&lt;BR&gt;Once that is done, changing the Connection at runtime can easily be done as shown below:&lt;/P&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
         font-size:12px;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;
&lt;PRE class=csharpcode&gt;DataSet1TableAdapters.CustomersTableAdapter adapter = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; DataSet1TableAdapters.CustomersTableAdapter();
SqlConnection conn = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; SqlConnection();
conn.ConnectionString = MyConnectionManager.ConnectionString;
adapter.Connection = conn;
DataTable table = adapter.GetData();&lt;/PRE&gt;
&lt;P&gt;What if an ObjectDataSource were using this TableAdapter and we wanted to change the ConnectionString at runtime? &lt;/P&gt;
&lt;P&gt;The ObjectDataSource, thankfully,&amp;nbsp;exposes an ObjectCreated event. This event gets raised after the object specified by the TypeName property is created.&amp;nbsp;&amp;nbsp;We can obtain a reference to this object by the ObjectInstance property exposed by the ObjectDataSourceEventArgs object. The Connection property can then be changed with a little sprinkle of reflection as shown below:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; ObjectDataSource1_ObjectCreated(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, ObjectDataSourceEventArgs e)
{
    &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (e.ObjectInstance != &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;)
    {
        SqlConnection conn = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; SqlConnection();
        conn.ConnectionString = MyConnectionManager.ConnectionString;
        e.ObjectInstance.GetType().GetProperty(&lt;SPAN class=str&gt;"Connection"&lt;/SPAN&gt;).SetValue(e.ObjectInstance, conn, &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;);
    }
}&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;This is useful in places where you wanted to set the ConnectionString&amp;nbsp;to use&amp;nbsp;based on the role of the web user. As always, if you know of a better way to do this, please post a comment. Thanks.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2662487" width="1" height="1"&gt;</description><enclosure url="http://weblogs.asp.net/rajbk/attachment/2662487.ashx" length="20775" type="image/gif" /><category domain="http://weblogs.asp.net/rajbk/archive/tags/Data/default.aspx">Data</category><category domain="http://weblogs.asp.net/rajbk/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/rajbk/archive/tags/ADO.NET/default.aspx">ADO.NET</category></item><item><title>GridView DropDownList Pager</title><link>http://weblogs.asp.net/rajbk/archive/2006/08/14/GridView-DropDownList-Pager.aspx</link><pubDate>Mon, 14 Aug 2006 15:18:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:469366</guid><dc:creator>rajbk</dc:creator><slash:comments>51</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/rajbk/rsscomments.aspx?PostID=469366</wfw:commentRss><comments>http://weblogs.asp.net/rajbk/archive/2006/08/14/GridView-DropDownList-Pager.aspx#comments</comments><description>&lt;p&gt;This post shows you how to add a custom DropDownlist pager and pager buttons&amp;nbsp;to the GridView as shown below:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.flickr.com/photos/47036843@N00/215101374/" title="Photo Sharing"&gt;&lt;img alt="gridview_dropdown_pager" border="0" height="171" src="http://static.flickr.com/83/215101374_1c76f0ded2_o.gif" width="631" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Unlike the behavior of the default pager buttons,&amp;nbsp; these buttons get disabled instead of being hidden (depending on the state of the GridView). &lt;/p&gt;&lt;p&gt;IMHO, buttons that remain at the same position while paging through a resultset makes a better UI (spatial memory). &lt;/p&gt;&lt;p&gt;The code is pretty straightforward. &lt;/p&gt;&lt;p&gt;Add the following pager template to your GridView.&lt;/p&gt;&lt;div style="font-size: 8pt; background: white; color: black; font-family: Courier New"&gt;&lt;p style="margin: 0px"&gt;&amp;lt;PagerTemplate&amp;gt;Goto Page &lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;asp:DropDownList ID=&lt;span style="color: maroon"&gt;&amp;quot;ddlPageSelector&amp;quot;&lt;/span&gt; runat=&lt;span style="color: maroon"&gt;&amp;quot;server&amp;quot;&lt;/span&gt; AutoPostBack=&lt;span style="color: maroon"&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&amp;gt;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/asp:DropDownList&amp;gt;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;asp:Button Text=&lt;span style="color: maroon"&gt;&amp;quot;First&amp;quot;&lt;/span&gt; CommandName=&lt;span style="color: maroon"&gt;&amp;quot;Page&amp;quot;&lt;/span&gt; CommandArgument=&lt;span style="color: maroon"&gt;&amp;quot;First&amp;quot;&lt;/span&gt; runat=&lt;span style="color: maroon"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ID=&lt;span style="color: maroon"&gt;&amp;quot;btnFirst&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;asp:Button Text=&lt;span style="color: maroon"&gt;&amp;quot;Previous&amp;quot;&lt;/span&gt; CommandName=&lt;span style="color: maroon"&gt;&amp;quot;Page&amp;quot;&lt;/span&gt; CommandArgument=&lt;span style="color: maroon"&gt;&amp;quot;Prev&amp;quot;&lt;/span&gt; runat=&lt;span style="color: maroon"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ID=&lt;span style="color: maroon"&gt;&amp;quot;btnPrevious&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;asp:Button Text=&lt;span style="color: maroon"&gt;&amp;quot;Next&amp;quot;&lt;/span&gt; CommandName=&lt;span style="color: maroon"&gt;&amp;quot;Page&amp;quot;&lt;/span&gt; CommandArgument=&lt;span style="color: maroon"&gt;&amp;quot;Next&amp;quot;&lt;/span&gt; runat=&lt;span style="color: maroon"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ID=&lt;span style="color: maroon"&gt;&amp;quot;btnNext&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;asp:Button Text=&lt;span style="color: maroon"&gt;&amp;quot;Last&amp;quot;&lt;/span&gt; CommandName=&lt;span style="color: maroon"&gt;&amp;quot;Page&amp;quot;&lt;/span&gt; CommandArgument=&lt;span style="color: maroon"&gt;&amp;quot;Last&amp;quot;&lt;/span&gt; runat=&lt;span style="color: maroon"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ID=&lt;span style="color: maroon"&gt;&amp;quot;btnLast&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;lt;/PagerTemplate&amp;gt; &lt;/p&gt;&lt;/div&gt;&lt;p style="margin: 0px"&gt;&lt;br /&gt;Add a RowCreated event handler to your GridView and add the following code:&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="font-size: 8pt; background: white; color: black; font-family: Courier New"&gt;&lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; GridView1_RowCreated(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, &lt;span style="color: teal"&gt;GridViewRowEventArgs&lt;/span&gt; e) {&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (e.Row.RowType == &lt;span style="color: teal"&gt;DataControlRowType&lt;/span&gt;.Pager) {&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal"&gt;PresentationUtils&lt;/span&gt;.&lt;strong&gt;SetPagerButtonStates&lt;/strong&gt;(GridView1, e.Row, &lt;span style="color: blue"&gt;this&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px"&gt;}&lt;/p&gt;&lt;/div&gt;&amp;nbsp; &lt;p style="margin: 0px"&gt;Finally, add the following code to your common class (PresentationUtils in my case)&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="font-size: 8pt; background: white; color: black; font-family: Courier New"&gt;&lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; &lt;strong&gt;SetPagerButtonStates&lt;/strong&gt;(&lt;span style="color: teal"&gt;GridView&lt;/span&gt; gridView, &lt;span style="color: teal"&gt;GridViewRow&lt;/span&gt; gvPagerRow, &lt;span style="color: teal"&gt;Page&lt;/span&gt; page) {&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;int&lt;/span&gt; pageIndex = gridView.PageIndex;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;int&lt;/span&gt; pageCount = gridView.PageCount;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal"&gt;Button&lt;/span&gt; btnFirst = (&lt;span style="color: teal"&gt;Button&lt;/span&gt;)gvPagerRow.FindControl(&lt;span style="color: maroon"&gt;&amp;quot;btnFirst&amp;quot;&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal"&gt;Button&lt;/span&gt; btnPrevious = (&lt;span style="color: teal"&gt;Button&lt;/span&gt;)gvPagerRow.FindControl(&lt;span style="color: maroon"&gt;&amp;quot;btnPrevious&amp;quot;&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal"&gt;Button&lt;/span&gt; btnNext = (&lt;span style="color: teal"&gt;Button&lt;/span&gt;)gvPagerRow.FindControl(&lt;span style="color: maroon"&gt;&amp;quot;btnNext&amp;quot;&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal"&gt;Button&lt;/span&gt; btnLast = (&lt;span style="color: teal"&gt;Button&lt;/span&gt;)gvPagerRow.FindControl(&lt;span style="color: maroon"&gt;&amp;quot;btnLast&amp;quot;&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; btnFirst.Enabled = btnPrevious.Enabled = (pageIndex != 0);&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; btnNext.Enabled = btnLast.Enabled = (pageIndex &amp;lt; (pageCount - 1));&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal"&gt;DropDownList&lt;/span&gt; ddlPageSelector = (&lt;span style="color: teal"&gt;DropDownList&lt;/span&gt;)gvPagerRow.FindControl(&lt;span style="color: maroon"&gt;&amp;quot;ddlPageSelector&amp;quot;&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ddlPageSelector.Items.Clear();&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;for&lt;/span&gt; (&lt;span style="color: blue"&gt;int&lt;/span&gt; i = 1; i &amp;lt;= gridView.PageCount; i++) {&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ddlPageSelector.Items.Add(i.ToString());&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ddlPageSelector.SelectedIndex = pageIndex;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;//Anonymous method (see another way to do this at the bottom)&lt;/strong&gt;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ddlPageSelector.SelectedIndexChanged += &lt;span style="color: blue"&gt;delegate&lt;/span&gt; {&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; gridView.PageIndex = ddlPageSelector.SelectedIndex;&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; gridView.DataBind();&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/p&gt;&lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px"&gt;} &lt;/p&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;AFAIK, VB.net 2.0 does not support anonymous methods. Therefore, for those of you converting this code to VB.net, you will need to add the handler manually. Go to the GridView Tasks and select &amp;quot;Edit templates&amp;quot;, select the PagerTemplate and double click on the DropDownList to add a index changed event handler. In the event handler, write the VB.net equivalent of this:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: 'Courier New'"&gt;protected&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt;&lt;font color="#000000"&gt; ddlPageSelector_SelectedIndexChanged(&lt;/font&gt;&lt;span style="color: blue"&gt;object&lt;/span&gt;&lt;font color="#000000"&gt; sender, &lt;/font&gt;&lt;span style="color: #2b91af"&gt;EventArgs&lt;/span&gt;&lt;font color="#000000"&gt; e) {&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'"&gt;&lt;font color="#000000"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;GridView1.PageIndex = ((&lt;/font&gt;&lt;span style="color: #2b91af"&gt;DropDownList&lt;/span&gt;&lt;font color="#000000"&gt;)sender).SelectedIndex;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'"&gt;&lt;font color="#000000"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;GridView1.DataBind();&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'"&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;p&gt;Related : &lt;a href="http://weblogs.asp.net/rajbk/archive/2006/08/04/Clickable-GridView-Headers.aspx"&gt;Clickable GridView Headers&lt;/a&gt; .&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=469366" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rajbk/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/rajbk/archive/tags/Data/default.aspx">Data</category><category domain="http://weblogs.asp.net/rajbk/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/rajbk/archive/tags/Tips/default.aspx">Tips</category></item></channel></rss>