我想从RowDeleting事件 中的GridView获取 Id ,我尝试这样:
protected void gvHouse_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Guid hholder = (Guid)(e.Values[0]);
using (var dataContext = new realtydbEntities())
{
var house = (from h in dataContext.Households.Include("aspnet_Users.aspnet_Membership")
where h.HouseholdID == hholder
select h).First();
dataContext.DeleteObject(house);
dataContext.SaveChanges();
}
}
但它不起作用。
匿名类型是这样的,我使用 List< this anonymousType > 绑定到GridView的数据源:
new
{
Id = u.HouseholdID,
BuNo = u.Building.BuildingName,
UnNo = u.UnitNo,
DepNo = u.DepartmentNo,
Name = u.aspnet_Users.UserName,
Corp = u.Corporation,
IdNumber = u.IdNumber,
Telephone = u.Telephone,
OtherHouseMembers = u.OtherHouseMembers,
OtherInfo = u.OtherInfo,
CrDate = u.aspnet_Users.aspnet_Membership.CreateDate
});
我想获取匿名对象或只是获取 ID 属性的值。