隐藏数据网格的列 (asp.net/c#)

发布于 2024-09-30 12:48:12 字数 489 浏览 8 评论 0原文

嘿,我正在尝试使我的数据网格可打印。为此,我试图隐藏最后 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

给我一枪 2024-10-07 12:48:12

如果您有 AutoGenerateColumns="True",那么只需设置visible=False 就无法使它们不可见,因为 自动生成的绑定列字段不会添加到 Columns 集合中

VB.Net,但我想你明白了:

Private Sub setPrinterView()
  For Each tr As TableRow In DirectCast(Me.GridView1.Controls(0), Table).Rows
      For i As Int32 = 1 To 4
          If tr.Cells.Count - i < 0 Then Exit For
          tr.Cells(tr.Cells.Count - i).Visible = False
      Next
   Next
End Sub

如果 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:

Private Sub setPrinterView()
  For Each tr As TableRow In DirectCast(Me.GridView1.Controls(0), Table).Rows
      For i As Int32 = 1 To 4
          If tr.Cells.Count - i < 0 Then Exit For
          tr.Cells(tr.Cells.Count - i).Visible = False
      Next
   Next
End Sub

If AutogenerateColumns is set to False you only need to make the Columns invisible without rebinding the Grid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文