Here I have created sample that may help you out.
HTML
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function Print() {
var count = $('[id*=tblCustomer]').length;
var pagebreakcount = 4;
var i = 1;
$('[id*=tblCustomer]').each(function () {
if (i % pagebreakcount == 0) {
$(this).attr('style', 'page-break-after: always');
}
i++;
});
var divContents = document.getElementById("dvCustomers").innerHTML;
var printWindow = window.open('', '', 'height=200,width=400');
printWindow.document.write(divContents);
printWindow.document.close();
printWindow.print();
Redirect();
};
function Redirect() {
setTimeout(function () {
location.href = location.href;
}, 5000);
}
</script>
<asp:Button ID="btnPrint" Text="Print" runat="server" OnClick="Print" />
<br />
<div id="dvCustomers">
<asp:DataList ID="dlCustomers" runat="server" RepeatColumns="3">
<ItemTemplate>
<table id="tblCustomer">
<tr>
<td>
<b><u>
<%# Eval("ContactName") %></u></b>
</td>
</tr>
<tr>
<td class="body">
<b>City: </b>
<%# Eval("City") %><br />
<b>Postal Code: </b>
<%# Eval("PostalCode") %><br />
<b>Country: </b>
<%# Eval("Country")%><br />
<b>Phone: </b>
<%# Eval("Phone")%><br />
<b>Fax: </b>
<%# Eval("Fax")%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</div>
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetCustomers();
}
}
protected void Print(object sender, EventArgs e)
{
dlCustomers.RepeatColumns = 1;
this.ClientScript.RegisterStartupScript(this.GetType(), "Print", "Print()", true);
}
private void GetCustomers()
{
string constring = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 15 ContactName,City,PostalCode,Country,Phone,Fax FROM Customers", con))
{
cmd.CommandType = CommandType.Text;
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
dlCustomers.DataSource = dt;
dlCustomers.DataBind();
}
}
}
Screenshot
