我有两张桌子,它们是父子。testtypes(Id,Name), testusers(Id,TypeId,Name) 我想在 gridview 中更新它们。testusers(名称字段)已更新,但 testTypes(testtype.Name 字段)未更新。也不例外。(我检查了 GridviewUpdated 处理程序中的 e.exception == null 变量。)我真的很困惑!太奇怪了。我认为 vs 2012 有错误!这是我的标记和代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="Ahooratech.WebForm4" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="gv" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="LinqDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="testtype.Name" HeaderText="mytypid" />
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="Ahooratech.DAL.DataClasses1DataContext" EnableUpdate="True" EntityTypeName="" TableName="testusers">
</asp:LinqDataSource>
</div>
</form>
</body>
</html>
和:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Ahooratech
{
public partial class WebForm4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
gv.rowUpdated += handler;
}
void gv_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
if (e.exception == null)
{
resultlbl.text = "Update seccessfully";// i get this message and name update in db
}
}
}
}
和 DAL:
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="AhooraTechdb")]
public partial class DataClasses1DataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
public DataClasses1DataContext() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["AhooraTechdbConnectionString1"].ConnectionString, mappingSource)
{
OnCreated();
}
public DataClasses1DataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public DataClasses1DataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public DataClasses1DataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public DataClasses1DataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public System.Data.Linq.Table<AdminUser> AdminUsers
{
get
{
return this.GetTable<AdminUser>();
}
}
public System.Data.Linq.Table<WishProduct> WishProducts
{
get
{
return this.GetTable<WishProduct>();
}
}
public System.Data.Linq.Table<Advertisement> Advertisements
{
get
{
return this.GetTable<Advertisement>();
}
}
public System.Data.Linq.Table<aspnet_Application> aspnet_Applications
{
get
{
return this.GetTable<aspnet_Application>();
}
}
public System.Data.Linq.Table<aspnet_Membership> aspnet_Memberships
{
get
{
return this.GetTable<aspnet_Membership>();
}
}
public System.Data.Linq.Table<aspnet_SchemaVersion> aspnet_SchemaVersions
{
get
{
return this.GetTable<aspnet_SchemaVersion>();
}
}
public System.Data.Linq.Table<aspnet_User> aspnet_Users
{
get
{
return this.GetTable<aspnet_User>();
}
}
public System.Data.Linq.Table<BillingType> BillingTypes
{
get
{
return this.GetTable<BillingType>();
}
}
public System.Data.Linq.Table<BoolValue> BoolValues
{
get
{
return this.GetTable<BoolValue>();
}
}
public System.Data.Linq.Table<ContainerItem> ContainerItems
{
get
{
return this.GetTable<ContainerItem>();
}
}
public System.Data.Linq.Table<Container> Containers
{
get
{
return this.GetTable<Container>();
}
}
public System.Data.Linq.Table<Country> Countries
{
get
{
return this.GetTable<Country>();
}
}
public System.Data.Linq.Table<DeliveryTimeType> DeliveryTimeTypes
{
get
{
return this.GetTable<DeliveryTimeType>();
}
}
public System.Data.Linq.Table<DeliveryType> DeliveryTypes
{
get
{
return this.GetTable<DeliveryType>();
}
}
public System.Data.Linq.Table<DescriptiveValue> DescriptiveValues
{
get
{
return this.GetTable<DescriptiveValue>();
}
}
public System.Data.Linq.Table<DiscountCode> DiscountCodes
{
get
{
return this.GetTable<DiscountCode>();
}
}
public System.Data.Linq.Table<DiscountCodesPrice> DiscountCodesPrices
{
get
{
return this.GetTable<DiscountCodesPrice>();
}
}
public System.Data.Linq.Table<DiscountcodesProduct> DiscountcodesProducts
{
get
{
return this.GetTable<DiscountcodesProduct>();
}
}
public System.Data.Linq.Table<DiscountCodesUser> DiscountCodesUsers
{
get
{
return this.GetTable<DiscountCodesUser>();
}
}
public System.Data.Linq.Table<DiscountType> DiscountTypes
{
get
{
return this.GetTable<DiscountType>();
}
}
public System.Data.Linq.Table<MeasurmentValue> MeasurmentValues
{
get
{
return this.GetTable<MeasurmentValue>();
}
}
public System.Data.Linq.Table<ProductImage> ProductImages
{
get
{
return this.GetTable<ProductImage>();
}
}
public System.Data.Linq.Table<ProductOption> ProductOptions
{
get
{
return this.GetTable<ProductOption>();
}
}
public System.Data.Linq.Table<ProductProductOption> ProductProductOptions
{
get
{
return this.GetTable<ProductProductOption>();
}
}
public System.Data.Linq.Table<Product> Products
{
get
{
return this.GetTable<Product>();
}
}
public System.Data.Linq.Table<ProductsCat> ProductsCats
{
get
{
return this.GetTable<ProductsCat>();
}
}
public System.Data.Linq.Table<ProductsDescriptionImage> ProductsDescriptionImages
{
get
{
return this.GetTable<ProductsDescriptionImage>();
}
}
public System.Data.Linq.Table<ProductsPeripheralProduct> ProductsPeripheralProducts
{
get
{
return this.GetTable<ProductsPeripheralProduct>();
}
}
public System.Data.Linq.Table<ProductsProperty> ProductsProperties
{
get
{
return this.GetTable<ProductsProperty>();
}
}
public System.Data.Linq.Table<ProductsRelatedProduct> ProductsRelatedProducts
{
get
{
return this.GetTable<ProductsRelatedProduct>();
}
}
public System.Data.Linq.Table<Property> Properties
{
get
{
return this.GetTable<Property>();
}
}
public System.Data.Linq.Table<PropertyCat> PropertyCats
{
get
{
return this.GetTable<PropertyCat>();
}
}
public System.Data.Linq.Table<RetrurnedOrder> RetrurnedOrders
{
get
{
return this.GetTable<RetrurnedOrder>();
}
}
public System.Data.Linq.Table<ReturnCause> ReturnCauses
{
get
{
return this.GetTable<ReturnCause>();
}
}
public System.Data.Linq.Table<ShippingType> ShippingTypes
{
get
{
return this.GetTable<ShippingType>();
}
}
public System.Data.Linq.Table<ShortDescriptiveValue> ShortDescriptiveValues
{
get
{
return this.GetTable<ShortDescriptiveValue>();
}
}
public System.Data.Linq.Table<SqlDataType> SqlDataTypes
{
get
{
return this.GetTable<SqlDataType>();
}
}
public System.Data.Linq.Table<State> States
{
get
{
return this.GetTable<State>();
}
}
public System.Data.Linq.Table<StatesShippingType> StatesShippingTypes
{
get
{
return this.GetTable<StatesShippingType>();
}
}
public System.Data.Linq.Table<StockStateType> StockStateTypes
{
get
{
return this.GetTable<StockStateType>();
}
}
public System.Data.Linq.Table<test> tests
{
get
{
return this.GetTable<test>();
}
}
public System.Data.Linq.Table<Unit> Units
{
get
{
return this.GetTable<Unit>();
}
}
public System.Data.Linq.Table<UserRequestProduct> UserRequestProducts
{
get
{
return this.GetTable<UserRequestProduct>();
}
}
public System.Data.Linq.Table<User> Users
{
get
{
return this.GetTable<User>();
}
}
public System.Data.Linq.Table<Warranty> Warranties
{
get
{
return this.GetTable<Warranty>();
}
}
public System.Data.Linq.Table<SideBarMenuItem> SideBarMenuItems
{
get
{
return this.GetTable<SideBarMenuItem>();
}
}
public System.Data.Linq.Table<OrderItem> OrderItems
{
get
{
return this.GetTable<OrderItem>();
}
}
public System.Data.Linq.Table<UserAddress> UserAddresses
{
get
{
return this.GetTable<UserAddress>();
}
}
public System.Data.Linq.Table<Basket> Baskets
{
get
{
return this.GetTable<Basket>();
}
}
public System.Data.Linq.Table<ElseCost> ElseCosts
{
get
{
return this.GetTable<ElseCost>();
}
}
public System.Data.Linq.Table<OrderStatuse> OrderStatuses
{
get
{
return this.GetTable<OrderStatuse>();
}
}
public System.Data.Linq.Table<ShipmentStatuse> ShipmentStatuses
{
get
{
return this.GetTable<ShipmentStatuse>();
}
}
public System.Data.Linq.Table<ConfirmStatuse> ConfirmStatuses
{
get
{
return this.GetTable<ConfirmStatuse>();
}
}
public System.Data.Linq.Table<PaymentStatuse> PaymentStatuses
{
get
{
return this.GetTable<PaymentStatuse>();
}
}
public System.Data.Linq.Table<Order> Orders
{
get
{
return this.GetTable<Order>();
}
}
public System.Data.Linq.Table<testtype> testtypes
{
get
{
return this.GetTable<testtype>();
}
}
public System.Data.Linq.Table<testuser> testusers
{
get
{
return this.GetTable<testuser>();
}
}
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.FetchProperties")]
public ISingleResult<FetchPropertiesResult> FetchProperties([global::System.Data.Linq.Mapping.ParameterAttribute(Name="ProductId", DbType="Int")] System.Nullable<int> productId)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), productId);
return ((ISingleResult<FetchPropertiesResult>)(result.ReturnValue));
}
}
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.testtypes")]
public partial class testtype : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _Id;
private string _Name;
private EntitySet<testuser> _testusers;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnIdChanging(int value);
partial void OnIdChanged();
partial void OnNameChanging(string value);
partial void OnNameChanged();
#endregion
public testtype()
{
this._testusers = new EntitySet<testuser>(new Action<testuser>(this.attach_testusers), new Action<testuser>(this.detach_testusers));
OnCreated();
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Id", DbType="Int NOT NULL", IsPrimaryKey=true)]
public int Id
{
get
{
return this._Id;
}
set
{
if ((this._Id != value))
{
this.OnIdChanging(value);
this.SendPropertyChanging();
this._Id = value;
this.SendPropertyChanged("Id");
this.OnIdChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Name", DbType="NVarChar(50)")]
public string Name
{
get
{
return this._Name;
}
set
{
if ((this._Name != value))
{
this.OnNameChanging(value);
this.SendPropertyChanging();
this._Name = value;
this.SendPropertyChanged("Name");
this.OnNameChanged();
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="testtype_testuser", Storage="_testusers", ThisKey="Id", OtherKey="TypeId")]
public EntitySet<testuser> testusers
{
get
{
return this._testusers;
}
set
{
this._testusers.Assign(value);
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private void attach_testusers(testuser entity)
{
this.SendPropertyChanging();
entity.testtype = this;
}
private void detach_testusers(testuser entity)
{
this.SendPropertyChanging();
entity.testtype = null;
}
}
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.testusers")]
public partial class testuser : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _Id;
private string _Name;
private System.Nullable<int> _TypeId;
private EntityRef<testtype> _testtype;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnIdChanging(int value);
partial void OnIdChanged();
partial void OnNameChanging(string value);
partial void OnNameChanged();
partial void OnTypeIdChanging(System.Nullable<int> value);
partial void OnTypeIdChanged();
#endregion
public testuser()
{
this._testtype = default(EntityRef<testtype>);
OnCreated();
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Id", DbType="Int NOT NULL", IsPrimaryKey=true)]
public int Id
{
get
{
return this._Id;
}
set
{
if ((this._Id != value))
{
this.OnIdChanging(value);
this.SendPropertyChanging();
this._Id = value;
this.SendPropertyChanged("Id");
this.OnIdChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Name", DbType="NVarChar(50)")]
public string Name
{
get
{
return this._Name;
}
set
{
if ((this._Name != value))
{
this.OnNameChanging(value);
this.SendPropertyChanging();
this._Name = value;
this.SendPropertyChanged("Name");
this.OnNameChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_TypeId", DbType="Int")]
public System.Nullable<int> TypeId
{
get
{
return this._TypeId;
}
set
{
if ((this._TypeId != value))
{
if (this._testtype.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnTypeIdChanging(value);
this.SendPropertyChanging();
this._TypeId = value;
this.SendPropertyChanged("TypeId");
this.OnTypeIdChanged();
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="testtype_testuser", Storage="_testtype", ThisKey="TypeId", OtherKey="Id", IsForeignKey=true)]
public testtype testtype
{
get
{
return this._testtype.Entity;
}
set
{
testtype previousValue = this._testtype.Entity;
if (((previousValue != value)
|| (this._testtype.HasLoadedOrAssignedValue == false)))
{
this.SendPropertyChanging();
if ((previousValue != null))
{
this._testtype.Entity = null;
previousValue.testusers.Remove(this);
}
this._testtype.Entity = value;
if ((value != null))
{
value.testusers.Add(this);
this._TypeId = value.Id;
}
else
{
this._TypeId = default(Nullable<int>);
}
this.SendPropertyChanged("testtype");
}
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public partial class FetchPropertiesResult
{
private int _ProdPropId;
private string _propertyName;
private string _UnitName;
private string _propertyCatName;
private string _sqlType;
private string _stringVal;
private string _shortStringVal;
private System.Nullable<int> _measurmentVal;
private System.Nullable<bool> _boolVal;
private int _OrderId;
public FetchPropertiesResult()
{
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ProdPropId", DbType="Int NOT NULL")]
public int ProdPropId
{
get
{
return this._ProdPropId;
}
set
{
if ((this._ProdPropId != value))
{
this._ProdPropId = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_propertyName", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]
public string propertyName
{
get
{
return this._propertyName;
}
set
{
if ((this._propertyName != value))
{
this._propertyName = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UnitName", DbType="NVarChar(50)")]
public string UnitName
{
get
{
return this._UnitName;
}
set
{
if ((this._UnitName != value))
{
this._UnitName = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_propertyCatName", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]
public string propertyCatName
{
get
{
return this._propertyCatName;
}
set
{
if ((this._propertyCatName != value))
{
this._propertyCatName = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_sqlType", DbType="NVarChar(20) NOT NULL", CanBeNull=false)]
public string sqlType
{
get
{
return this._sqlType;
}
set
{
if ((this._sqlType != value))
{
this._sqlType = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_stringVal", DbType="NVarChar(MAX)")]
public string stringVal
{
get
{
return this._stringVal;
}
set
{
if ((this._stringVal != value))
{
this._stringVal = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_shortStringVal", DbType="NVarChar(100)")]
public string shortStringVal
{
get
{
return this._shortStringVal;
}
set
{
if ((this._shortStringVal != value))
{
this._shortStringVal = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_measurmentVal", DbType="Int")]
public System.Nullable<int> measurmentVal
{
get
{
return this._measurmentVal;
}
set
{
if ((this._measurmentVal != value))
{
this._measurmentVal = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_boolVal", DbType="Bit")]
public System.Nullable<bool> boolVal
{
get
{
return this._boolVal;
}
set
{
if ((this._boolVal != value))
{
this._boolVal = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_OrderId", DbType="Int NOT NULL")]
public int OrderId
{
get
{
return this._OrderId;
}
set
{
if ((this._OrderId != value))
{
this._OrderId = value;
}
}
}
}