Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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;
}


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?
Posted
Updated 6-Jan-11 11:12am
v3
Comments
Sandeep Mewara 6-Jan-11 15:16pm    
the value gets set back to the original value -> Sure you are not rebinding the grid before the event triggers?
[DK]KiloDunse 6-Jan-11 15:18pm    
It's just this value that gets returned to the original. Alle other updates fine

Please try changing the column's Nullable property in the EF designer from (None) to True.

Hope that helps.
 
Share this answer
 
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>
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900