How to Hide gridview Allow paging While taking print
I want to hide the allow paging while taking the print out. once the print is taken the the allow paging should view for navigating to the next page. help.....
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Javeed M ShaikhPosted Nov 11, 2011, 10:35 AM
replace with this code and try...
GridView1.AllowPaging = false;
GridView1.DataBind();
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.RenderControl(hw);
string gridHTML = sw.ToString().Replace("\"", "'")
.Replace(System.Environment.NewLine, "");
StringBuilder sb = new StringBuilder();
sb.Append("");
ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
GridView1.AllowPaging = true;
BindGrid();
You need to override the rendering event also like this, since the .net compiler thinks that the control is not added to the form and is rendered, hence it throws an error even if your GridView control is inside a form with runat = "server".
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
Rajkumar RPosted Nov 11, 2011, 12:07 AM
protected void btnPrint_Click(object sender, EventArgs e)
{
int count = GridView1.PageCount;
if (count == GridView1.PageIndex + 1)
{
GridView1.EmptyDataRowStyle.Font.Bold = true;
GridView1.FooterRow.Visible = true;
}
else
{
GridView1.FooterRow.Visible = false;
}
//GridView1.PagerSettings.Visible = false;
GridView1.AllowPaging = false;
//GridView1.BottomPagerRow.Visible = false;
GridView1.FooterRow.Font.Bold = true;
Response.Write("");
BindGrid();
GridView1.AllowPaging = true;
}
once finally i set as true, paging shown in the printing time also..
please post any help
Rajkumar RPosted Nov 11, 2011, 12:01 AM
Javeed M ShaikhPosted Nov 10, 2011, 9:58 AM
did you try...
before you print..
GridView1.PagerSettings.Visible = false;
after printing is done...
GridView1.PagerSettings.Visible = true;
if the above does not work, try to set the BottomPagerRow.Visible property.