Hi everyone, I am new to C# and I require help printing the contents of a grid view on an aspx webpage.
At present I have a print button placed on the page where the Grid View is positioned. This print button has been programmed via html. The current button prints the whole web page contents including the menu bar and the print button itself, rather than the grid view only.
Is it possible to only print a grid view on an aspx page? If so I would be extremely grateful if someone could guide me through the steps to achieve this in a simple yet effective way.
I'm unsure whether the print command should be coded into the html page or the C# behind code.
I welcome any feedback, Many thanks.
Loading
Rishikesh Kumar SinghPosted Feb 22, 2013, 1:59 AM
put the following javascript function on your head section
and call this function on click of the button
it will definitely help you out.
If it helps you then please mark it as an accepted answer otherwise let me know i will send you the code.
Lynn EmeryPosted Feb 22, 2013, 6:14 AM
The content of the grid view is controlled by drop down lists and is controlled via an sql data source. Could this be the reason as to why that code isn't enforcing a title?
Rishikesh Kumar SinghPosted Feb 22, 2013, 5:53 AM
protected void GridView1_DataBound(object sender, EventArgs e)
Lynn EmeryPosted Feb 22, 2013, 5:21 AM
I now have the print button working!
If I want to add a title to the print page how would I do this?
I pressume I need to add it somewhere between this code:
Var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1');
prtwin.document.write(prtGrid.outerHTML);
prtwin.document.close();
prtwin.focus();
prtwin.print();
prtwin.close();
}
Lynn EmeryPosted Feb 22, 2013, 5:14 AM
I have added the button code, however when i run the program I get the following error
"Microsoft JScript runtime error: 'printItn' is undefined"
Below is the code which I pasted in from your reply. I also get rather a lot of errors within the aspx page including prtgrid, prtwin and var are not a known CSS property name and " Missing a colon (':') between the property and value in the "
I'm not sure if i am getting the errors because I have pasted the code in the wrong place.
Thank you for your reply, sorry to keep bothering you with questions.Rishikesh Kumar SinghPosted Feb 22, 2013, 4:33 AM
<asp:Button ID="btnPrint" Runat="server" Text="Print" OnClientClick="printItn();" />
and let me know
Lynn EmeryPosted Feb 22, 2013, 2:28 AM
I have added the code to the header section of my javasrcipt, but I am unsure how to recall that code on a button click. I pressume I have to recall the function prinItn () somehow?
Also when copying the code a lot of errors appear such as prtwin is not a known CC property value.
Thanks for your help/