GridView 不可见行显示在空数据行中

发布于 2024-11-29 03:01:09 字数 206 浏览 3 评论 0原文

我有一个自定义 GridView,默认显示 6 行数据(无论有多少行),底部有一个分页器。该 Gridview 用于许多独特的页面。在一个页面上,我有一列设置为隐藏(宽度为 0 且 Css-Display=none),这是我需要的——程序的另一部分取决于它的设置方式。

该列在有数据的行中不可见(因为它不应该如此)。但是,该列在空行中显示为空列(不应可见)。我将如何使空行也隐藏列?

I have a custom GridView that will show 6 rows of data as a default (regardless of how many rows) with a pager at the bottom. This Gridview is used for numerous unique pages. On one page, I have a column that I set to hidden (width 0 and Css-Display=none) that I need -- another part of program depends on it being set that way.

The column is NOT visible in rows where there is data (as it shouldn't be). However, the column is showing up in the empty rows as an empty column (should not be visible). How would I go about making the EMPTY rows hide the COLUMN as well?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

云之铃。 2024-12-06 03:01:09

听起来您有一些自定义实现来显示空行(因此始终显示 6 个),该实现可能使用与常规行不同的模板,或者可能根本没有模板。问题很可能是您的空行定义没有将 width 和 css 属性应用于隐藏列。

您可以发布您如何实现显示空行的功能吗?

It sounds like you have some custom implementation to display empty rows (so 6 are always displayed) that probably uses a different template than the regular rows or possibly no template at all. The problem is most likely that your empty row definition is not applying the width and css properties to the hidden column.

Can you post the how you implemented the feature to show empty rows?

属性 2024-12-06 03:01:09

如果有人仍在寻找此问题的简单答案,我已经发布了此内容

您可以使用 GridView 的 OnRowCreated 事件并将空行的 columnspan 值指定为可见列数。请参阅下面的示例代码

protected void grd_RowCreated(object sender, GridViewRowEventArgs e)
        {
             if (e.Row.RowType == DataControlRowType.EmptyDataRow)
                e.Row.Cells[0].ColumnSpan = 7; // number of visible columns;
        }

I have posted this if any one still searching simple answer for this Question

You can use the OnRowCreated event of GridView and specify the columnspan value of the empty row as number of visible column. See the below sample code

protected void grd_RowCreated(object sender, GridViewRowEventArgs e)
        {
             if (e.Row.RowType == DataControlRowType.EmptyDataRow)
                e.Row.Cells[0].ColumnSpan = 7; // number of visible columns;
        }
dawn曙光 2024-12-06 03:01:09

在我的 GridView_DataBound 函数中,为存在的每一列生成单元格 - 它如何填充空单元格。我添加了 if 语句来检查该字段是否应该隐藏,并确保自动生成的单元格也被隐藏。

foreach (DataControlField field in _gridView.Columns)
{
    TableCell cell = new TableCell();
    cell.Text = " ";

    if (field.ItemStyle.CssClass == "hideGridColumn")
        cell.Visible = false;

    row.Cells.Add(cell);
}

In my GridView_DataBound function, the cells were being generated for each column that existed -- how it filled in the empty cells. I added the if statement to check if the field was supposed to be hidden, and ensure the autogenerated cell was hidden as well.

foreach (DataControlField field in _gridView.Columns)
{
    TableCell cell = new TableCell();
    cell.Text = " ";

    if (field.ItemStyle.CssClass == "hideGridColumn")
        cell.Visible = false;

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