Reputation:
I have a DevExpress GridControl which contains many columns. Now during Print/Export i want to hide one column. Whats the logic? How can i do that?
Upvotes: 0
Views: 1000
Reputation: 2434
protected void PrintAllPages(object sender, EventArgs e)
{
GridView1.AllowPaging = false;
GridView1.DataBind();
GridView1.HeaderRow.Cells[9].Visible = false;
GridView1.FooterRow.Cells[9].Visible = false;
// Loop through the rows and hide the cell in the first column
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
row.Cells[9].Visible = false;
}
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
hw.AddStyleAttribute(HtmlTextWriterStyle.Direction, "rtl");
GridView1.RenderControl(hw);
string gridHTML = sw.ToString().Replace("\"", "'")
.Replace(System.Environment.NewLine, "");
StringBuilder sb = new StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload = new function(){");
sb.Append("var printWin = window.open('', '', 'left=0");
sb.Append(",top=0,width=1000,height=600,status=0');");
sb.Append("printWin.document.write(\"");
sb.Append(gridHTML);
sb.Append("\");");
sb.Append("printWin.document.close();");
sb.Append("printWin.focus();");
sb.Append("printWin.print();");
sb.Append("printWin.close();};");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
GridView1.AllowPaging = true;
GridView1.DataBind();
}
protected void PrintCurrentPage(object sender, EventArgs e)
{
GridView1.PagerSettings.Visible = false;
GridView1.DataBind();
GridView1.HeaderRow.Cells[9].Visible = false;
GridView1.FooterRow.Cells[9].Visible = false;
// Loop through the rows and hide the cell in the first column
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
row.Cells[9].Visible = false;
}
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
hw.AddStyleAttribute(HtmlTextWriterStyle.Direction, "rtl");
GridView1.RenderControl(hw);
string gridHTML = sw.ToString().Replace("\"", "'")
.Replace(System.Environment.NewLine, "");
StringBuilder sb = new StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload = new function(){");
sb.Append("var printWin = window.open('', '', 'left=0");
sb.Append(",top=0,width=1000,height=600,status=0');");
sb.Append("printWin.document.write(\"");
sb.Append(gridHTML);
sb.Append("\");");
sb.Append("printWin.document.close();");
sb.Append("printWin.focus();");
sb.Append("printWin.print();");
sb.Append("printWin.close();};");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
GridView1.PagerSettings.Visible = true;
GridView1.DataBind();
}
Upvotes: 1
Reputation: 1639
In click event you can hide the column.
Each GridView
column has the Visible and VisibleIndex
properties. You can simply turn off the Visible property to hide a column and turn it back on to show it again.If you set this property to -1
, a column becomes hidden as well.
void HideColumn(object sender, EventArgs e)
{
colToHide.Visible=false;
}
PrintPreview shows the same columns as the source grid. The columns to show are taken at the moment of generating a document. You can hide required columns by setting Visible to false, when calling the CreateDocument method
of the VisualDataNodeLink
.
Refer this link for more information https://www.devexpress.com/Support/Center/Question/Details/Q312869
Upvotes: 0