ASPxGridView1用法<二>

发布时间:2020-06-24 20:05:07 作者:温馨梦痕
来源:网络 阅读:3083

关于ASPxGridView1添加子项事件,今天上网查了好久,没有找到合适,最后看己摸所,得到了结果,贴出来,希望能给大家有所帮助。

首先是修改属性如图

ASPxGridView1用法<二>

然后,再编辑模板,

ASPxGridView1用法<二>

 

ASPxGridView1用法<二>

这样就搞定了,接下来,就是添加子项控件

<div>
        <dx:ASPxGridView ID="grid" runat="server" KeyFieldName="sheet_no" AutoGenerateColumns="False"
            ClientIDMode="AutoID" OnSelectionChanged="Page_Load" OnDataBound="grid_DataBound"
            OnFocusedRowChanged="grid_FocusedRowChanged" OnDetailRowExpandedChanged="grid_DetailRowExpandedChanged"
            OnDetailsChanged="grid_DetailsChanged" Width="490px">
            <ClientSideEvents FocusedRowChanged="function(s, e) { }" RowClick="function(s, e) {
    OnGridFocusedRowChanged();
}" />
            <Columns>
                <dx:GridViewDataTextColumn Caption="单号" FieldName="sheet_no" Name="sheet_no" VisibleIndex="0">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Caption="供应商" FieldName="sup_no" Name="sup_no" VisibleIndex="1">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Caption="经办人" FieldName="order_man" Name="order_man" VisibleIndex="2">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Caption="操作人" FieldName="oper_id" Name="oper_id" VisibleIndex="3">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Caption="操作日期" FieldName="oper_date" Name="oper_date"
                    VisibleIndex="4">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Caption="总金额" FieldName="paid_amount" Name="paid_amount"
                    VisibleIndex="5">
                </dx:GridViewDataTextColumn>
                <dx:GridViewCommandColumn VisibleIndex="6" ShowSelectCheckbox="True">
                    <EditButton Visible="True" Text="编辑">
                    </EditButton>
                    <DeleteButton Visible="True" Text="删除">
                    </DeleteButton>
                </dx:GridViewCommandColumn>
            </Columns>
            <Templates>
                <DetailRow>
                    <dx:ASPxGridView ID="subGrid" runat="server" DataSourceID="SqlDataSource1">
                        <Columns>
                            <dx:GridViewDataTextColumn Caption="单号" FieldName="sheet_no" Name="sheet_no" VisibleIndex="0">
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn Caption="编号" FieldName="item_no" Name="item_no" VisibleIndex="1">
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn Caption="条码" FieldName="barcode" Name="barcode" VisibleIndex="2">
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn Caption="单位" FieldName="unit_no" Name="unit_no" VisibleIndex="3">
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn Caption="数量" FieldName="order_qnty" Name="item_name" VisibleIndex="4">
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn Caption="零售价" FieldName="in_price" Name="in_price" VisibleIndex="5">
                            </dx:GridViewDataTextColumn>
                        </Columns>
                    </dx:ASPxGridView>
                </DetailRow>
            </Templates>
            <SettingsBehavior AllowFocusedRow="True" ConfirmDelete="True" />
            <SettingsDetail ShowDetailRow="True" />
        </dx:ASPxGridView>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataReader">
        </asp:SqlDataSource>
    </div>

注意:红色为子项控件,另外在父控件中一定要邦定主键,KeyFieldName="sheet_no";

接下来就是后台邦定代码了,如何邦定我父控件,前面都说过了,接下来,我们看如何邦定子控件,因为子控件在后台调不出来,所以,我再加一个SqlDataSource控件,用它来邦定子控件,这个邦定要动态的去,在展开行事件中写

  private void NewMethod(int i)
    {
//得到主键值
        object var = this.grid.GetRowValues(i, new string[] { "sheet_no" });
        this.SqlDataSource1.DataSourceMode = SqlDataSourceMode.DataReader;
        this.SqlDataSource1.ConnectionString = "Server=.;DataBase=hjh02;uid=sa;pwd=1";
        this.SqlDataSource1.SelectCommand = string.Format("select * from lsps_bhqd where sheet_no='{0}'", var.ToString());
        this.SqlDataSource1.DataBind();
    }
//展开行事件

    protected void grid_DetailRowExpandedChanged(object sender, ASPxGridViewDetailRowEventArgs e)
    {
        NewMethod(e.VisibleIndex);
    }

 

ASPxGridView1用法<二>

 

 

 

推荐阅读:
  1. Linux 重定向符:> ,>>, <
  2. mysql中is 、is not和<=>的区别用法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

职场 休闲 aspxgridview1添加子项 as

上一篇: Oracle 学习之性能优化(八)优化器

下一篇:树的创建和遍历

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》