zoukankan      html  css  js  c++  java
  • 一个AspxGridView包含另一个AspxGridView实现主从数据绑定 程序员

    实现对象:产品(Products)、产品详情(ProductsDetails)、产品类型(Categorys)

    数据源:EntityDataSource

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

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

    显示代码
        <asp:EntityDataSource ID="EntityDataSource1" Include="ProductsDetails" runat="server" ConnectionString="name=ProductsEntities" DefaultContainerName="ProductsEntities" EnableFlattening="False" EntitySetName="Products" EnableDelete="True" EnableInsert="True" EnableUpdate="True">

    第二步:实现在产品编辑的时候用下拉框绑定产品类型(Categorys)

    在gvProducts里添加一个GridViewDataComboBoxColumn,直接用EntityDataSource绑定数据源

    gvProducts里的代码:

    显示代码
    <dx:GridViewDataComboBoxColumn Caption="Category" FieldName="Category"
                    VisibleIndex="3">
                    <PropertiesComboBox EnableSynchronization="False"
                        DataSourceID="EntityDataSource2" TextField="Category" ValueField="CId"
                        ValueType="System.String" />
                    <EditCellStyle HorizontalAlign="Left">
                    </EditCellStyle>
                </dx:GridViewDataComboBoxColumn>

    数据源代码

    显示代码
        <asp:EntityDataSource ID="EntityDataSource2" runat="server"
            ConnectionString="name=ProductsEntities" DefaultContainerName="ProductsEntities"
            EnableFlattening="False" EntitySetName="Categorys" EntityTypeFilter="Categorys">
        </asp:EntityDataSource>

    第三步:最为关键

    在页面的后台代码页面(List.aspx.cs)增加如下代码

    显示代码
    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";
                }
            }
    两年了,依然没有前进,是自己找不到方向,也是一份刻骨的考验。只好重新出发,为那个目标继续前进!
  • 相关阅读:
    ps 玻璃效果
    svn 官方下载
    svn
    c# form 无标题
    app Inventor google 拖放手机代码块
    paas
    java 延迟
    c# 执行 cmd
    c # xml操作 (无法将类型为“System.Xml.XmlComment”的对象强制转换为类型“System.Xml.XmlElement”)
    eclipse 安装插件 link方式
  • 原文地址:https://www.cnblogs.com/huangjing/p/3030780.html
Copyright © 2011-2022 走看看