您的位置:首页 > 编程语言 > ASP

一个AspxGridView包含另一个AspxGridView实现主从数据绑定

2013-04-19 15:08 555 查看
实现对象:产品(Products)、产品详情(ProductsDetails)、产品类型(Categorys)

数据源:EntityDataSource

第一步:产品的AspxGridView用EntityDataSource绑定所有数据,分别启用Insert,Delete,Update(这些功能的实现就在此省略了)

gvProducts的EntityDataSoure,注意一定要包含属性:Include,这个属性一定要绑定产品详情的实体类,即:Include="ProductsDetails"

显示代码

protected void gvProductsDetail_DataBinding(object sender, EventArgs e)
{
ASPxGridView gvDetail = sender as ASPxGridView;
if (gvDetail != null)
{
int i = Convert.ToInt32(gvDetail.GetMasterRowKeyValue());
ProductsDetails detail = db.ProductsDetails.First(pd => pd.PId == i);
List<ProductsDetails> list = new List<ProductsDetails>();
list.Add(detail);
gvDetail.DataSource = list;
gvDetail.KeyFieldName = "PId";
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐