update linq related table

2019-02-28 19:39发布

问题:

I have a User table like (Id,Name,UserAddresId) and UserAddress table like(Id,AddressOne) with a FormView Control and i want to have an update command in it. Here's my form:

    <asp:FormView ID="orderInfolst" runat="server" DataKeyNames="Id" DataSourceID="OrderSrc">
    <ItemTemplate>
     Name:
     <asp:Label ID="namelbl" runat="server" Text='<%# Eval("Name") %>' /> 
     User Address One 
     <asp:Label ID="namelbl" runat="server" Text='<%# Eval("UserAddresses.AddressOne") %>' />  
 <asp:Button ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="ویرایش" />    
</ItemTemplate>
    <EditTemplate>
     Name:
     <asp:TextBox ID="namelbl" runat="server" Text='<%# Bind("Name") %>' /> 
     User Address One; 
     <asp:TextBox ID="namelbl" runat="server" Text='<%# Bind("UserAddresses.AddressOne") %>' />
 <asp:Button ID="UpdateButton" runat="server"   CausesValidation="True" CommandName="Update"  Text="ویرایش شود" />
                          &nbsp;<asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="لغو شود" />

    </EditTemplate>

and in server I have a handler for ItemUpdated Event like this:

if (e.Exception == null)
{
    Resultlbl.Text = "update successfully ";
}
else 
{
    Resultlbl.Text = e.Exception.Message;
}    

I get the Update Successfully message. so Name filed updated but AddressOne in related Table not updated!!! what is wrong here?