input type="button" id="btnPrint" runat="server" value ="Print" onclick ="PrintReport();"/>
//Make one method for print
script type="text/javascript" language="javascript" >
function PrintReport() {
var bt = document.getElementById("btnPrint").style.display='block';
window.print()
}
/script>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ con.open();
SqlCommand cmd = new SqlCommand("select * from students", con);
SqlDataReader oDr = cmd.ExecuteReader();
if (oDr.HasRows)
{
StringBuilder sb = new StringBuilder();
sb.Append("
Financial Report | ||
---|---|---|
"); sb.Append("id".ToString()); sb.Append(" | ");
sb.Append(""); sb.Append("Name".ToString()); sb.Append(" | ");
sb.Append(""); sb.Append("Roll".ToString()); // finish the rest of the row sb.Append(" |
"); sb.Append(oDr["id"].ToString()); sb.Append(" | ");
sb.Append(""); sb.Append(oDr["Name"].ToString()); sb.Append(" | ");
sb.Append(""); sb.Append(oDr["Roll"].ToString()); // finish the rest of the row sb.Append(" |
Response.Write(sb);
con.close();
}
}
}
No comments:
Post a Comment