隐藏数据网格的列 (asp.net/c#)
嘿,我正在尝试使我的数据网格可打印。为此,我试图隐藏最后 4 列。我有一个可打印按钮,我想在单击该按钮时使最后 4 列消失。到目前为止我还没有成功完成这项工作。
我已经尝试过:
ProductsGrid.Columns[6].ControlStyle.Width = -1;
并
ProductsGrid.Columns[6].Visible = false;
注意:这些列中确实有数据。也许这是我的问题的一部分。另外,我需要列标题消失。
感谢您的任何提示。
编辑:我使它们在按钮单击命令中不可见。我没有使用生成的列,所以我认为它设置为 false。我对这个问题有点厌倦了,所以下班了,直到下周中旬才会回来,所以我可能不得不推迟到那时再寻找解决方案。谢谢大家的评论,我会尽快查看。抱歉,我无法及时提供更多反馈。
编辑x2:我是否必须以某种回发或其他方式处理它?
Hey, I am trying to make my datagrid printable. To do this, I am trying to hide the final 4 columns. I have a printable button that I would like to when clicked, make those last 4 columns disappear. I have so far failed to make this work.
I have tried:
ProductsGrid.Columns[6].ControlStyle.Width = -1;
and
ProductsGrid.Columns[6].Visible = false;
Note: these columns do have data in them. Perhaps that is part of my issue. Also, I need the headers of the columns to disappear.
Thanks for any tips.
EDIT: I am making them invisible in my button click command. I am not using generated columns, so I think that is set to false. I got a bit fed up with this issue and left work, and won't be back till mid next week, so I might have to hold off finding the solution till then. Thanks for the comments everyone, I will look it over soon. Sorry, I can't give more feedback in a timely fashion.
Edit x2: Do have I have to handle it in some sort of postback or something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有 AutoGenerateColumns="True",那么只需设置visible=False 就无法使它们不可见,因为 自动生成的绑定列字段不会添加到 Columns 集合中。
VB.Net,但我想你明白了:
如果 AutogenerateColumns 设置为 False,你只需要使列不可见,而不需要重新绑定网格。
If you have AutoGenerateColumns="True", then it does not work to make them invisible by simply set visible=False, because automatically generated bound column fields are not added to the Columns collection.
VB.Net, but i think you get the idea:
If AutogenerateColumns is set to False you only need to make the Columns invisible without rebinding the Grid.