Most of us would always use the export to Excel in the report viewer (90% of the time), rather than having a ‘Select a format’ option in it. I will be describing a simple method here to make the excel a default option for export in the report viewer.
One quick note: You can go to the rsreportserver.config file in “\Program Files\Microsoft SQL Server\MSRS10.DEV\Reporting Services\ReportServer” directory and move the Excel option to the top. Check the screenshot below:
Unfortunately, this will take the Excel to the top of the dropdown list options, but still the ‘select a format’ option will be the first option in the list. Check the screenshot below:
Now lets get back on track and see what the possible solution.
Problem: To set the Excel export as the default export option for the reportviewer on the load. Avoid resetting of dropdown options, after click of Export.
Solution: Consider the two controls in the context, the dropdown and the Export Link. They are simple html controls that gets rendered on the page. Onload of the page, we will set the selected index to 1 or 3 (depending on the position of Excel option, remember the option count starts from 0). Then make the “Export” link onclick event to null. Register a new set of javascript for the onclick of the “Export” link.
The reason why to bother much about the click of export link button is due to the fact that it will reset the dropdowns “selectedIndex = 0” blindly, which we don’t want.
Let me take you through the steps clearly:
Step 1: In your aspx page, which has reportviewer being loaded, add the script tag at the end. By end, i mean after the reportviewer tag. Do check the id of the rendered controls and modify it accordingly.
<rsweb:ReportViewer ID=”rpvMain” runat=”server” Font-Names=”Trebuchet MS, arial”
BackColor=”#FFFFFF” InternalBorderColor=”#CCCCCC” LinkDisabledColor=”Black” AsyncRendering=”true”
ProcessingMode=”Remote” SizeToReportContent=”false” ShowPrintButton=”false” ShowFindControls=”false”
Font-Size=”12px” Width=”970px” PromptAreaCollapsed=”false” Style=”text-align: left;display:inline;”>
</rsweb:ReportViewer><script language=”javascript” type=”text/javascript”>
function triggerExport() {
var formatDropDown = document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl00’);
if (formatDropDown.selectedIndex == 0)
return false;
window.open(document.getElementById(‘ctl00_cphMain_rpvMain’).ClientController.m_exportUrlBase + encodeURIComponent(formatDropDown.value), ‘_blank’)
formatDropDown.selectedIndex = 1; //Change this to the appropriate index of Excel in the dropdown
document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl01’).Controller.SetViewerLinkActive(document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl00’).selectedIndex != 0); return false;
}if (document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl00’) != null) {
document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl00’).selectedIndex = 1;//Change this to the appropriate index of Excel in the dropdown
document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl01’).onclick = null;
document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl01’).onclick = triggerExport;
}
</script>
Step 2: Run the page and check it.
NB: You can make it browser compatible, but i found it of no use, as the SSRS has loads of issues with the other browsers. Also, if you see the click event and other javascripts used in the SSRS controls, they all use document.getElementById. 😦 Quite depressing I know.
If you wish to make the document.getElementById usage safe acrross other browsers, use the following function call in your code:
function CustomGetElementById(elementId)
{
return document.getElementById
? document.getElementById(elementId)
: document.all
? document.all[elementId]
: document.layers[elementId];
}ex: CustomGetElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl01’).onclick = null;
If you wish to remove the ‘select a format‘ option you can now go ahead and do it. It would be just a small modification to the above functions. I leave that to you.
Hope this post was useful.
Jaipur is traditionally understood for colored gemstones specially
emeralds.
Hurrah, that’s what I was seawrching for, what a material!
present here at this weblog, thanks admin of this web site.
Hello, I would like to subscribe for this blog to obtain latest updates,
therefore where can i do it please assist.
Give yourself permission to enjoy an occasional dessert if your
diabetes is properly managed and under control. Sweets, junk
food, and sodas are not allowed on the DASH
diet. Apple cider vinegar has often been touted as a miracle remedy and it could prove true for diabetes.
Thanks , I haνe just been searching for information about this topic fߋr a wɦile and yours iѕ thе grdeatest I have
discovered till now. But, what in regardѕ to the bottom line?
Are you сertain cߋncerning the source?
If some one wants expert view regarding running a blog then i advise him/her to pay a quick visit this weblog, Keep up the good
job.
click this
SSRS: Making Excel the default export option for reportviewer | The Relentless FrontEnd – Aackose Lal’s Blog
please click the next post
SSRS: Making Excel the default export option for reportviewer | The Relentless FrontEnd – Aackose Lal’s Blog
online reputation management on social media
SSRS: Making Excel the default export option for reportviewer | The Relentless FrontEnd – Aackose Lal’s Blog
I go to see daily some web sites and information sites to read articles, but
this weblog presents feature based posts.
I loved as much as you’ll receive carried out right here.
The sketch is tasteful, your authored subject matter stylish.
nonetheless, you command get got an shakiness over that you wish
be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly very often inside case you shield this increase.
Good day! This post could not be written any better!
Reading through this post reminds me of my old room mate!
He always kept chatting about this. I will forward this post to him.
Fairly certain he will have a good read. Thank you for sharing!
It’s awesome in favor of me to have a site, which is helpful
designed for my know-how. thanks admin
It is the best time to make a few plans for the long ruun and it iis time to be happy.I have
read this put up and if I may just I want to suggest you
few fascinating issues or suggestions. Maybe you could
write next articles regarding this article. I desire to
learn more issues about it!
Very good article. I certainly love this site.Continue the good
work!
Saleh Stevens
SSRS: Making Excel the default export option for reportviewer | The Relentless FrontEnd – Aackose Lal’s Blog
Great article.
Hi there everyone, it’s my first go to see at this website, and piece of writing is in fact
fruitful designed for me, keep up posting these
types of articles.
Consolidated Credit
SSRS: Making Excel the default export option for reportviewer | The Relentless FrontEnd – Aackose Lal’s Blog
axzz3EB4RS5ej
SSRS: Making Excel the default export option for reportviewer | The Relentless FrontEnd – Aackose Lal’s Blog
Link Schwartz
SSRS: Making Excel the default export option for reportviewer | The Relentless FrontEnd – Aackose Lal’s Blog
When you think about it, that’s got to be the right answer.
(Author) | Hi Jojo,It’s not working baecuse you probably don’t have the html select dropdown on the page or you are using incorrect ID. In your code, you are using #myselect. This means that your HTML select dropdown MUST have an ID of myselect. Unless this is fixed, it won’t work.In order to help you, I have added a complete example that shows you exactly how to do it. Just refer to the example above and try it out let me know how that goes.
I am trying to dslabie one of option from select box using above code in IE6 , its not working for me..any idea?here is my code..oneTwoThree$(document).ready(function() {$( #sel option[value=’2′] ).attr( dslabied , dslabied );$( select option[disabled] ).css({ color’: #cccccc’}); $( select’).change(function() {if(this.options[this.selectedIndex].disabled) { if(this.options.length == 0) {this.selectedIndex = -1; } else {this.selectedIndex ; } $(this).trigger( change’);} }); $( select’).each(function(it) {if(this.options[this.selectedIndex].disabled) this.onchange(); });});
Thanks for this code!! You saved my heini (and just in time for XMas).
Hi,
Found a solution to my problem with the blank window.
Included a hidden Iframe in web page.
Passed the URL to the Iframe’s source instead of the window in triggerExport()-
document.getElementById(reportDownload).src = document.getElementById(“rvReportViewer”).ClientController.m_exportUrlBase + encodeURIComponent(formatDropDown.value);
Hope it helps somebody facing a similar issue.
Hi,
My client does’nt want to see a new blank window when a report is exported. Is there any other option for calling below code without opening a new window –
window.open(document.getElementById(‘ctl00_cphMain_rpvMain’).ClientController.m_exportUrlBase + encodeURIComponent(formatDropDown.value), ‘_blank’)
Thanks
Thanks!
This works fine until I click on the exportlink. I’m getting the error “‘m_exportUrlBase’ is null or not an object”. I did some research on the internet and the following suggestions did NOT solve my problem:
– Remove Ajax update panels (not applicable);
– Make the report viewer current page set to 1 (no effect);
Any idea?
Below my code…
Thanks!
Gert
function triggerExport()
{
var formatDropDown = document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl00’);
if (formatDropDown.selectedIndex == 0)
return false;
window.open(document.getElementById(‘rpvDobolav’).ClientController.m_exportUrlBase + encodeURIComponent(formatDropDown.value), ‘_blank’);
formatDropDown.selectedIndex = 1;
document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl01’).Controller.SetViewerLinkActive(document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl00’).selectedIndex != 0);
return false;
}
if (document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl00’) != null)
{
document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl00’).selectedIndex = 1;
document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl00’).style.display = ‘none’;
document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl01’).onclick = null;
document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl01’).onclick = triggerExport;
document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl01’).innerHTML = ‘Export to Excel’;
}
Let me assume you are using IE here.
1. Can you see if alert(document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl00′));
and document.getElementById(‘rpvDobolav′); is giving some [Object] result? If not, verify the ID values using IE Developer toolbar or view source.
2. Open IE developer toolbar (F12). Select mouse icon and select the ‘Export’ link button. In the toolbar, on the right side goto the ‘Attributes’ tag. Check the ‘onclick’ or ‘href’ attribute value. This is the javascript function getting called. Copy paste the function content once again and modify the changes mentioned above. See if it works. If not, then remove this whole implementation and see if it works directly by default. And then start over again.
Indeed I’m using IE (7)
I used your suggestion under 2 and catched the default onclick-handler of the exportlink after first removing my statement document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl01′).onclick = triggerExport;
I placed the logic in the functionbody of triggerExport and know it works. I don’t no why but it works and that’s great!
Thanks very much for your support!
Gert
Below my final solution given the user requirements:
– Only export to Excel
– Hide the listbox with formats and only show the link
function triggerExport()
{
var formatDropDown = document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl00’);
formatDropDown.selectedIndex = 1;
if (!ClientToolbarrpvDobolav_ctl01.HandleClientSideExport())
__doPostBack(‘rpvDobolav$ctl01$ctl05$ctl01’,”);
return false;
}
if (document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl00’) != null)
{
document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl00’).selectedIndex = 1;
document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl00’).style.display = ‘none’;
document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl01’).onclick = null;
document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl01’).onclick = triggerExport;
document.getElementById(‘rpvDobolav_ctl01_ctl05_ctl01’).innerHTML = ‘Export to Excel’;
}
Thanks mate it works, I had to replace to replace “ctl00_cphMain_rpvMain_ctl01_ctl05_ctl00” with the id generated by IE, excellent post. Keep up the good work.
I have done excatly same as mentioned in sreportserver.config and also below is my code but still I don’t get it working, can you please help? thanks for posting..
Code:
function triggerExport() {
var formatDropDown = document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl00’);
if (formatDropDown.selectedIndex == 0)
return false;
window.open(document.getElementById(‘ctl00_cphMain_rpvMain’).ClientController.m_exportUrlBase + encodeURIComponent(formatDropDown.value), ‘_blank’)
formatDropDown.selectedIndex = 1; //Change this to the appropriate index of Excel in the dropdown
document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl01’).Controller.SetViewerLinkActive(document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl00’).selectedIndex != 0); return false;
}
if (document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl00’) != null) {
document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl00’).selectedIndex = 1;//Change this to the appropriate index of Excel in the dropdown
document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl01’).onclick = null;
document.getElementById(‘ctl00_cphMain_rpvMain_ctl01_ctl05_ctl01’).onclick = triggerExport;
}
Some possible issues:
1. Open the page in IE developer toolbar (F12 in your IE browser) and select the dropdown. Check if the id is “ctl00_cphMain_rpvMain_ctl01_ctl05_ctl00”. If not change correct that value in the above function.
2. Is “ctl00_cphMain_rpvMain_ctl01_ctl05_ctl01” the ID of the “export” button? Can you verify that?
Hmm is anyone else eenpriexcing problems with thepictures on this blog loading? I’m trying to determine if its a problem on my end or if it’s the blog.Any suggestions would be greatly appreciated.[]Mr. Tumblr Reply:February 1st, 2013 at 11:58 amDo you mean tumblring.net or your own blog?[]
Kaixo:A mi me parece que falta otro punto, referido a la actuación de “los mercados” en general y a los bancos, en particular. En concreto, (y es un punto mÃnimo, muy mÃnimo), hace unos dÃas, la Union Europea echó la bronca al gobierno español, por no controlar las remuneraciones de los altos ejecutivos. A mi me parece vergonzoso que el Sr. Zapatero ni siquiera se haya atrevido a eso. ¡Pues hay que decirle que aplique esa directiva!Y, por otra parte, sugiero a todas/os que, como respuesta a la actuación de los bancos, que especulan ¡incluso! con las materias primas, ocasionando un incremento notable de l población hambrienta mundial, saquéis (al menos) una parte de vuestros dineros de los bancos tradicionales y la metais en la banca ética (TRIODOS BANK, FIARE), donde el dinero se destina a mejorar las condiciones de vida de diversos colectivos. Me parece que es una utilización MUUUUCHO MAS JUSTA que dedicarlo a la especulación, al tráfico de armas, etc., etc.Gracias. Eskerrik asko.
Leonard Cohen wrote many songs he has just finished a tour of the UK. Michael Bubl`e retnecly sung an incomplete version of Im your Man a great Cohen song-Yes! his song did top the list in the Chritmas 2008 hit parade-it was not sung by Cohen but a new arrangement sung by Alexandra BurkeThe name of tha song is: HALLELUJAH
First of all, thank you for redips.drag. It is fasainttc.Regarding posting complex data, a much simpler way of dealing with complex structures like tables, etc. is to do the following:1. In javascript, convert the table to a data object or array.2. Convert the object/array to a JSON string, e.g.: mystring=JSON.stringify(myObject, null, “\t”);3. URI-encode if necessary, e.g.: myURLparm=encodeURIComponent(mystring);4. Send it via AJAX using POST method.On the other end, PHP just does a json_decode() and everything is ready to go.