• Devexpress GridView内嵌dx:ASPxGridLookup取得控件值乱跳解决方案


    一 页面嵌入ASPxGridLookup控件

     <dx:ASPxGridView ID="gridDetail" runat="server"
                            KeyFieldName="ID"
                            OnRowInserting="gridDetail_RowInserting" >
                            <Columns>
                                <dx:GridViewCommandColumn Caption="操作" ButtonType="Image" Width="80px">
                                    <HeaderTemplate>
                                        <dx:ASPxButton ID="btnDetailInsert" Image-Url="../Scripts/easyui/themes/icons/edit_Add.png"
                                            ClientInstanceName="btnDetailInsert" AutoPostBack="true" runat="server" OnClick="btnDetailInsert_Click">
                                        </dx:ASPxButton>
                                    </HeaderTemplate>
                                    <DeleteButton Text="删除" Visible="true">
                                        <Image ToolTip="删除" Url="../Scripts/easyui/themes/icons/no.png" />
                                    </DeleteButton>
                                    <UpdateButton Text="保存" Visible="true">
                                        <Image ToolTip="保存" Url="../Scripts/easyui/themes/icons/filesave.png" />
                                    </UpdateButton>
                                    <EditButton Text="编辑" Visible="true">
                                        <Image ToolTip="编辑" Url="../Scripts/easyui/themes/default/images/tree_file.Gif" />
                                    </EditButton>
                                    <CancelButton Text="取消" Visible="true">
                                        <Image ToolTip="取消" Url="../Scripts/easyui/themes/icons/back.png" />
                                    </CancelButton>
                                </dx:GridViewCommandColumn>
                                <dx:GridViewDataTextColumn Caption="管理员" Width="100px" FieldName="GuideAdmin.Name"
                                    VisibleIndex="1">
                                    <EditItemTemplate>
                                        <dx:ASPxGridLookup ID="GridGuideAdmin" Width="100%" runat="server" IncrementalFilteringMode="StartsWith"
                                            TextFormatString="{1}" ClientInstanceName="GridGuideAdmin" OnInit="GridGuideAdmin_Init"
                                            KeyFieldName="ID">
                                            <Columns>
                                                <dx:GridViewDataTextColumn FieldName="CompanyCode" Caption="代码" />
                                                <dx:GridViewDataTextColumn FieldName="ShortName" Caption="管理员" />
                                            </Columns>
                                        </dx:ASPxGridLookup>
                                    </EditItemTemplate>
                                </dx:GridViewDataTextColumn>
                            </Columns>
    </dx:ASPxGridView>

    二 绑定ASPxGridLookup数据,没有Order By SQ则取到的数据会乱跳(这个花了半天才调出来)
     protected void GridGuideAdmin_Init(object sender, EventArgs e)
            {
                EmployeeRule employeeRule = new EmployeeRule();
                ((ASPxGridLookup)sender).DataSource =  employeeRule.GetEmployeeDataTable();
            }
           
            public DataTable GetEmployeeDataTable()
            {
                string sql = @"select
                            PersonName as ShortName,
                            Sq as ID,ADM_EmployeeCd as CompanyCode
                            from V_Employee order by SQ"; 
                return dao.GetDataTable(sql); ;
            }
            
    三、获得页面数据保存

     protected void gridDetail_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        //判断是否包含导游数据,不包含则根据需求人数从报价中带入
        guideAssignOrderItemInfo.GuideSq = new Guid((sender as ASPxGridView).GetMasterRowKeyValue().ToString());
                guideAssignOrderItemInfo.GuideAdmin.ID = Guid.Parse(GetColumnLookUpValue(gridDetail, "GuideAdmin.Name", "GridGuideAdmin"));
        this.SetDetailParameter(sender as ASPxGridView, e.NewValues);

        this.guideAssignOrderItemInfoRule.Add(guideAssignOrderItemInfo);
        e.Cancel = true;
        (sender as ASPxGridView).CancelEdit();
        this.grid.Focus();
    }


    public string GetColumnLookUpValue(ASPxGridView grv, string strColumn, string strControlFieldName)
    {//从下拉框得到Sq值
        ASPxGridLookup control = (ASPxGridLookup)grv.FindEditRowCellTemplateControl((GridViewDataColumn)grv.Columns[strColumn], strControlFieldName);
        if (control != null && control.Value != null)
        {
            return control.Value.ToString();
        }
        return Guid.Empty.ToString();
    }

  • 相关阅读:
    LeetCode 931. Minimum Falling Path Sum
    LeetCode 1. Two Sum
    LeetCode 72. Edit Distance
    命令行发送SMTP协议邮件(163邮箱)
    商品销量分析及预测系统测试心得
    商品销量预测 第一次迭代总结
    【Codeforces 126B】Password
    【Codeforces 466C】Number of Ways
    【CodeCraft-19 and Codeforces Round #537 (Div. 2) C】Creative Snap
    【Codeforces Global Round 1 E】Magic Stones
  • 原文地址:https://www.cnblogs.com/eugenewu0808/p/3580680.html
Copyright © 2020-2023  润新知