here is the steps:
1) create simple web application (here i used asp.net with C#).
2) put following control in to Page.
1) Gridview (id = GridView1)
2) html button (id =Button1)
<inputid=”Button1″type=”button”value=”Print”language=”javascript”onclick=”return Button1_onclick()” />
<asp:GridViewID=”GridView1″runat=”server”>
</asp:GridView>
3) fill data into GridView
//here i used the list you can bind with database also
System.Collections.Generic.List<string> obj = newSystem.Collections.Generic.List<string>();
for(inti = 0; i < 10; i++)
{
obj.Add(i.ToString());
}
GridView1.DataSource = obj;
GridView1.DataBind();
4) now write the print function. click on the Button1 or write Java Script.
<script language="javascript" type="text/javascript"> <!-- function Button1_onclick() { //open new window set the height and width =0,set windows position at bottom var a = window.open ('','','left =' + screen.width + ',top=' + screen.height + ',width=0,height=0,toolbar=0,scrollbars=0,status=0'); //write gridview data into newly open window a.document.write(document.getElementById('<%= GridView1.ClientID %>').innerHTML); a.document.close(); a.focus(); //call print a.print(); a.close(); return false; } // --> </script>
Thanks
Leave a reply to sandy Cancel reply