Click here to Skip to main content
14,426,851 members
Rate this:
Please Sign up or sign in to vote.
In windows application I use the following javascript code to print a datagridview 'gvuserinfo'.
The form runs without error but I could not see the 'print' button. The same javascript code with web page works fine. How to solve this?

public MaterialsToBeReadyReport()
        {
con.ConnectionString = Constring;
InitializeComponent();
webBrowser1.DocumentText =
@"<html><head>
<script type='text/javascript'>
function PrintGridData() {
var prtGrid = document.getElementById('<%=gvUserInfo.ClientID %>');
prtGrid.border = 0;
var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=500,height=500,tollbar=0,scrollbars=1,status=0,resizable=1');
prtwin.document.write(prtGrid.outerHTML);
prtwin.document.close();
prtwin.focus();
prtwin.print();
prtwin.close();
}
</script>
</head><body></body></html>";
webBrowser1.Document.InvokeScript("PrintGridData");
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You cannot use JavaScript code in windows forms - at least not directly.
You can run JavaScript in an html control.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,078
Richard MacCutchan 1,729
phil.o 1,260
Patrice T 1,187
MadMyche 1,015



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100