TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ok ok
NA
34
3.8k
Page break after each record changes in specific row C#
Oct 28 2016 5:41 AM
Experts,<br /> <br /> Is it possible to have the page break after every records changes in the rows while printing gridview using C#.<br /> <br /><div> please advise..</div><div> </div><div>tried,<div class="dp-highlighter"><ol start="1" class="dp-c"><li class="alt"><span><span class="keyword">protected</span><span> </span><span class="keyword">void</span><span> Print(</span><span class="keyword">object</span><span> sender, EventArgs e) </span></span></li><li class=""><span>{ </span></li><li class="alt"><span> </span></li><li class=""><span> GridView2.UseAccessibleHeader = <span class="keyword">true</span><span>; </span></span></li><li class="alt"><span> GridView2.HeaderRow.TableSection = TableRowSection.TableHeader; </span></li><li class=""><span> GridView2.FooterRow.TableSection = TableRowSection.TableFooter; </span></li><li class="alt"><span> GridView2.Attributes[<span class="string">"style"</span><span>] = </span><span class="string">"border-collapse:separate"</span><span>; </span></span></li><li class=""><span> <span class="keyword">string</span><span> preffered_name = </span><span class="string">""</span><span>; </span></span></li><li class="alt"><span> <span class="keyword">foreach</span><span> (GridViewRow row </span><span class="keyword">in</span><span> GridView2.Rows) </span></span></li><li class=""><span> { </span></li><li class="alt"><span> </span></li><li class=""><span> String grid_dept = row.Cells[2].Text; </span></li><li class="alt"><span> <span class="keyword">if</span><span> (</span><span class="keyword">string</span><span>.IsNullOrEmpty(preffered_name)) </span></span></li><li class=""><span> preffered_name = grid_dept; </span></li><li class="alt"><span> <span class="keyword">if</span><span> (preffered_name != grid_dept) </span></span></li><li class=""><span> { </span></li><li class="alt"><span> row.Attributes[<span class="string">"style"</span><span>] = </span><span class="string">"page-break-after:always;"</span><span>; </span></span></li><li class=""><span> StringWriter sw = <span class="keyword">new</span><span> StringWriter(); </span></span></li><li class="alt"><span> HtmlTextWriter hw = <span class="keyword">new</span><span> HtmlTextWriter(sw); </span></span></li><li class=""><span> GridView2.RenderControl(hw); </span></li><li class="alt"><span> <span class="keyword">string</span><span> gridHTML = sw.ToString().Replace(</span><span class="string">"\""</span><span>, </span><span class="string">"'"</span><span>).Replace(System.Environment.NewLine, </span><span class="string">""</span><span>); </span></span></li><li class=""><span> StringBuilder sb = <span class="keyword">new</span><span> StringBuilder(); </span></span></li><li class="alt"><span> sb.Append(<span class="string">"<script type = 'text/javascript'>"</span><span>); </span></span></li><li class=""><span> sb.Append(<span class="string">"window.onload = new function(){"</span><span>); </span></span></li><li class="alt"><span> sb.Append(<span class="string">"var printWin = window.open('', '', 'left=0"</span><span>); </span></span></li><li class=""><span> sb.Append(<span class="string">",top=0,width=3000,height=600,status=0');"</span><span>); </span></span></li><li class="alt"><span> sb.Append(<span class="string">"printWin.document.write(\""</span><span>); </span></span></li><li class=""><span> <span class="keyword">string</span><span> style = </span><span class="string">"thead {display:table-header-group;} tfoot{display:table-footer-group;}"</span><span>; </span></span></li><li class="alt"><span> sb.Append(style + gridHTML); </span></li><li class=""><span> sb.Append(<span class="string">"\");"</span><span>); </span></span></li><li class="alt"><span> sb.Append(<span class="string">"printWin.document.close();"</span><span>); </span></span></li><li class=""><span> sb.Append(<span class="string">"printWin.focus();"</span><span>); </span></span></li><li class="alt"><span> sb.Append(<span class="string">"printWin.print();"</span><span>); </span></span></li><li class=""><span> sb.Append(<span class="string">"printWin.close();"</span><span>); </span></span></li><li class="alt"><span> sb.Append(<span class="string">"};"</span><span>); </span></span></li><li class=""><span> sb.Append(<span class="string">"</script>"</span><span>); </span></span></li><li class="alt"><span> ClientScript.RegisterStartupScript(<span class="keyword">this</span><span>.GetType(), </span><span class="string">"GridPrint"</span><span>, sb.ToString()); </span></span></li><li class=""><span> <span class="comment">// GridView2.DataBind();preffered_name</span><span> </span></span></li><li class="alt"><span> preffered_name = grid_dept; </span></li><li class=""><span> } </span></li><li class="alt"><span> </span></li><li class=""><span> </span></li><li class="alt"><span> } </span></li><li class=""><span> </span></li><li class="alt"><span>} </span></li><li class=""><span> </span></li><li class="alt"><span><span class="keyword">int</span><span> tempcounter = 0; </span></span></li><li class=""><span> </span></li><li class="alt"><span><span class="keyword">protected</span><span> </span><span class="keyword">void</span><span> GridView2_RowDataBound(</span><span class="keyword">object</span><span> sender, GridViewRowEventArgs e) </span></span></li><li class=""><span>{ </span></li><li class="alt"><span> <span class="keyword">if</span><span> (e.Row.RowType == DataControlRowType.DataRow) </span></span></li><li class=""><span> { </span></li><li class="alt"><span> tempcounter = tempcounter + 1; </span></li><li class=""><span> <span class="keyword">if</span><span> (tempcounter == 10) </span></span></li><li class="alt"><span> { </span></li><li class=""><span> e.Row.Attributes.Add(<span class="string">"style"</span><span>, </span><span class="string">"page-break-after: always;"</span><span>); </span></span></li><li class="alt"><span> tempcounter = 0; </span></li><li class=""><span> } </span></li><li class="alt"><span> } </span></li><li class=""><span>} </span></li><li class="alt"><span> </span></li><li class=""><span> </span></li><li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">override</span><span> </span><span class="keyword">void</span><span> VerifyRenderingInServerForm(Control control) </span></span></li><li class=""><span>{ </span></li><li class="alt"><span> <span class="comment">/* Verifies that the control is rendered */</span><span> </span></span></li><li class=""><span>} <br /></span></li></ol></div> </div>
Reply
Answers (
2
)
File Upload Control Accept Only Images
Is it Possible to upload and download the .EXE file