Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I have some data in grid view. If i have some spaces in gridview data it is showing perfect look in normal time. When am i taking print that data is auto split. Please give me some help for this issue.

Before Print Data:
ExamName	ExamDate	Telugu	Hindi	English	Mathematics	Science	Social Studies	Total	%	
MODEL TEST 1	06-01-14	48/50	49/50	47/50	 48/50	 49/50	 47/50	 288/300	96	
MODEL TEST 2	03-02-14	46/50	40/50	48/50	 50/50	 42/50	 43/50	 269/300	89.67	
MODEL TEST 3	17-02-14	43/50	43/50	45/50	 48/50	 49/50	 43/50	 271/300	90.33	
MODEL TEST 4	10-03-14	35/50	36/50	37/50	 38/50	 35/50	 38/50	 219/300	73	
MODEL TEST 5	24-03-14	42/50	43/50	44/50	 45/50	 43/50	 42/50	 259/300	86.33	
MODEL TEST 6	31-03-14	35/50	36/50	37/50	 45/50	 42/50	 48/50	 243/300	81	
MODEL TEST 7	07-04-14	40/50	44/50	45/50	 46/50	 41/50	 48/50	 264/300	88	
MODEL TEST 8	14-04-14	47/50	45/50	46/50	 48/50	 49/50	 42/50	 277/300	92.33	1

Please see above recors. i hv space in exams and exam date also 14-04-14 like this. When i am taking this print data will be coming like this.

Ex:
MODEL 14-
TEST 04-
1 14 .


Plese give me good solution.Below is the print code.

C#
public void PrintWebControl(Control ctrl, string Script)
{
    StringWriter stringWrite = new StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
    if (ctrl is WebControl)
    {
        Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;
    }
    Page pg = new Page();
    pg.EnableEventValidation = false;
    if (Script != string.Empty)
    {
        pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
    }
    HtmlForm frm = new HtmlForm();
    pg.Controls.Add(frm);
    frm.Attributes.Add("runat", "server");
    frm.Controls.Add(ctrl);
    pg.DesignerInitialize();
    pg.RenderControl(htmlWrite);
    string strHTML = stringWrite.ToString();
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.Write(strHTML);
    HttpContext.Current.Response.Write("<script>window.print();</script>");
    // HttpContext.Current.Response.End();

}

Thanking you,
hari
Posted
v3
Comments
[no name] 15-May-14 6:01am    
show your code
Hari Krishna Prasad Inakoti 15-May-14 6:47am    
public void PrintWebControl(Control ctrl, string Script)
{
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
if (ctrl is WebControl)
{
Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;
}
Page pg = new Page();
pg.EnableEventValidation = false;
if (Script != string.Empty)
{
pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
}
HtmlForm frm = new HtmlForm();
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ctrl);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
// HttpContext.Current.Response.End();

}
DipsMak 15-May-14 7:26am    
where is code to print and print and page properties

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900