Gridview_RowUpdating没有将null设置为newvalue [英] Gridview_RowUpdating not setting null to newvalue

查看:69
本文介绍了Gridview_RowUpdating没有将null设置为newvalue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用实体数据源(EF4)进行选择,更新和删除的gridview.

我在某些列中使用下拉框.

在RowUpdating方法中,我获得了下拉框的selectedvalue并检查了该值.

如果值为"0",则将NewValue设置为Null,如下所示:

I have a gridview that uses entitydatasource (EF4) to select, update and delete.

I use dropdownboxes in some columns.

In the RowUpdating method, I get the selectedvalue of the dropdownbox and check the value.

If the value is "0" then I set the NewValue to be Null like this:

        protected void gwTestProducts_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            DropDownList ddlTestUser = ((DropDownList)((GridView)sender).Rows[e.RowIndex].FindControl("ddlTestUser"));
            int testUserID = int.Parse(ddlTestUser.SelectedValue);
            e.NewValues["TestUserID"] = testUserID != 0 ? (int?)testUserID : null;
}



该代码将NewValues ["TestUserID"]设置为null,但是当EF执行此操作时,该..值将重新设置为原始值.

如果我选择的值不是"0",则代码可以正常工作.




The code sets the NewValues["TestUserID"] to null, but when EF does it''s stuff.. the value gets set back to the original value.

If I select a value, other than "0", the code works fine.


Any idea whats wrong?

推荐答案

请尝试将EF设计器中列的Nullable属性从(无)更改为True.

希望能对您有所帮助.
Please try changing the column''s Nullable property in the EF designer from (None) to True.

Hope that helps.


已经是:

Already is:

/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::system.int32 xmlns:global="#unknown"> TestUserID
{
    get
    {
        return _TestUserID;
    }
    set
    {
        OnTestUserIDChanging(value);
        ReportPropertyChanging("TestUserID");
        _TestUserID = StructuralObject.SetValidValue(value);
        ReportPropertyChanged("TestUserID");
        OnTestUserIDChanged();
    }
}
private Nullable<global::system.int32> _TestUserID;
partial void OnTestUserIDChanging(Nullable<global::system.int32> value);
partial void OnTestUserIDChanged();</global::system.int32></global::system.int32></global::system.int32>


发现了问题.

我没有在gridview的EditItemTemplate中绑定该属性.因此,属性TestUserID不在gridviews"BoundFieldValues"集合中.

结果,该属性未由EntityDataSource更新.
Found the problem.

I did not bind the property too anything in the EditItemTemplate in the gridview. Therefore, the property TestUserID did not get in the gridviews "BoundFieldValues" collection.

As a result, the property did not get updated by the EntityDataSource.


这篇关于Gridview_RowUpdating没有将null设置为newvalue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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