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

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

问题描述

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



编辑:我试过隐藏的字段选项,但它仍然将值设置为null。我已经看过页面源代码和隐藏的字段存在与适当的值...

解决方案

我发现此解决方案在.Net 2.0中模拟隐藏列:

实现GridView.RowCreated事件。

  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'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.

EDIT: 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...

解决方案

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

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;
}

Here's the link: http://www.beansoftware.com/ASP.NET-Tutorials/GridView-Hidden-Column.aspx

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天全站免登陆