ASP.NET:当列不可见时,GridView 值设置为 null [英] ASP.NET: GridView value set to null when column is not visible

查看:22
本文介绍了ASP.NET:当列不可见时,GridView 值设置为 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用对象列表作为 GridView 的数据源,当我将列设置为不可见时,更新失败,因为这些列的值更改为 null(并且该列不允许为 null).当列可见时,这些值确实存在,但我真的不想显示这些列,因为在大多数情况下,它们是用户并不真正需要看到的 ID 列.

I'm using a list of objects as the data source of my GridView and when I set columns to not be visible the updates fail because the value of those columns is changed to null (and the column doesn't allow nulls). The values do exist when the columns are visible but I really don't want to display these columns because, for the most part, they are ID columns that the user doesn't really need to see.

我已经尝试了隐藏字段选项,但它仍然将值设置为空.我查看了页面源代码,并且隐藏字段存在适当的值...

I've tried the hidden field option but it still sets the value to null. I've looked at the page source and the hidden field exists with the appropriate value...

推荐答案

我找到了这个解决方案来模拟 .Net 2.0 中的隐藏列:

I found this solution to simulate hidden columns in .Net 2.0:

实现 GridView.RowCreated 事件.

Implement the GridView.RowCreated event.

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

这是链接:http://www.beansoftware.com/ASP.NET-Tutorials/GridView-Hidden-Column.aspx

我猜在 2.0 中,当一列不可见时,该列的数据绑定会失败,但此方法会在建立链接后隐藏,因此它会欺骗系统 (?).

I guess in 2.0 when a column is not visible the databinding fails for that column but this method hides after the link has been established so it tricks the system (?).

这篇关于ASP.NET:当列不可见时,GridView 值设置为 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆