简体   繁体   English

在网格视图中隐藏列但不隐藏页码 asp.net

[英]Hiding columns but not page number in grid view asp.net

I am currently working on a grid view.我目前正在研究网格视图。 I am using the allow paging method which is working fine and positioned to the right of the grid view.我正在使用允许分页方法,该方法工作正常并位于网格视图的右侧。

I want to hide the first column which is working fine except it also removing the paging numbers which stops the user from being able to change page numbers.我想隐藏工作正常的第一列,除了它还删除了阻止用户更改页码的分页号码。

Below is the code I am using to hide the column下面是我用来隐藏列的代码

protected void tblLog_RowCreated(object sender, GridViewRowEventArgs e)
{
    e.Row.Cells[0].Visible = false;
}

The above code hides the correct column but also hides the automatic page numbers created by the grid view allowpaging method.上面的代码隐藏了正确的列,但也隐藏了由网格视图 allowpaging 方法创建的自动页码。

Thanks for any help you can provide.感谢您的任何帮助,您可以提供。

Check first to see if it's actually a data row:首先检查它是否实际上是一个数据行:

if (e.Row.RowType == DataControlRowType.DataRow)
{
    e.Row.Cells[0].Visible = false;
}

You need to add a condition for datarow and dataheader both您需要为 datarow 和 dataheader 添加条件

if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
            e.Row.Cells[0].Visible = false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM