我有一个包含许多列的DevExpress GridControl。现在在打印/导出期间我想隐藏一列。什么是逻辑?我怎么能这样做?
答案 0 :(得分:0)
在点击事件中,您可以隐藏该列。
每个GridView
列都有Visible and VisibleIndex
个属性。您只需关闭Visible属性即可隐藏列并将其重新打开以再次显示。如果将此属性设置为-1
,则列也会隐藏。
void HideColumn(object sender, EventArgs e)
{
colToHide.Visible=false;
}
PrintPreview显示与源网格相同的列。要显示的列是在生成文档时拍摄的。在调用CreateDocument method
的{{1}}时,您可以通过将Visible设置为false来隐藏所需的列。
有关详细信息,请参阅此链接https://www.devexpress.com/Support/Center/Question/Details/Q312869
答案 1 :(得分:0)
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();
}