• 如何使用编辑模板在ASPxGridView中进行新增修改(除去常规的gridviw模板编辑外)


    aspgridview模板编辑效果图:

    模板编辑效果图

    //前端代码:(核心: <Templates><EditForm>.....中间可用栅格样式布局等(随意)...</Templates></EditForm>)

    //其中文本控件赋值为:

    <dx:ASPxSpinEdit ID="SE_BEGINAREA" runat="server" Number='<%# Eval("BEGINAREA") !=null ? decimal.Parse(Eval("BEGINAREA").ToString()) : 0%>' MinValue="0" NumberType="Float" Width="100%">
    </dx:ASPxSpinEdit>

    <dx:ASPxGridView ID="ASPxGridView" KeyFieldName="TPUSHMONEY_ID" runat="server" ClientInstanceName="grid" Theme="Mulberry"
    AutoGenerateColumns="False" Width="100%"
    OnRowInserting="ASPxGridView_RowInserting"
    OnRowUpdating="ASPxGridView_RowUpdating">
    <ClientSideEvents EndCallback="grid_EndCallback" />
    <SettingsText EmptyDataRow="暂无数据" />
    <Styles>
    <%--<AlternatingRow Enabled="True" />
    <Header HorizontalAlign="Center" />
    <CommandColumn Spacing="10px" Wrap="False" />--%>
    
    <Table CssClass="tw-dataTable"></Table>
    <Header CssClass="tw-dtheader" HorizontalAlign="Center"></Header>
    
    <CommandColumn CssClass="tw-commandColumn"></CommandColumn>
    <CommandColumnItem CssClass="tw-commandColumnBtn"></CommandColumnItem>
    <FocusedRow CssClass="tw-focusRow"></FocusedRow>
    </Styles>
    <Settings GridLines="Horizontal" />
    <SettingsPager PageSize="10" />
    <SettingsBehavior AllowFocusedRow="True" />
    <SettingsEditing Mode="PopupEditForm">
    </SettingsEditing>
    <SettingsPopup>
    <%--<CustomizationWindow HorizontalAlign="WindowCenter" VerticalAlign="WindowCenter" />--%>
    <EditForm Modal="true" HorizontalAlign="WindowCenter" VerticalAlign="WindowCenter" />
    <%-- <HeaderFilter ResizingMode="Postponed" />--%>
    </SettingsPopup>
    <Columns>
    <dx:GridViewDataTextColumn Caption="序号" VisibleIndex="1" Width="100px">
    <EditFormSettings Visible="False" />
    <CellStyle HorizontalAlign="Center"></CellStyle>
    <DataItemTemplate>
    <dx:ASPxLabel ID="L_rowid_1" runat="server" Text='<%# Container.ItemIndex + 1 %>'>
    </dx:ASPxLabel>
    </DataItemTemplate>
    </dx:GridViewDataTextColumn>
    <dx:GridViewDataColumn FieldName="BEGINAREA" Caption="交易金额区间(起始)" VisibleIndex="2" Width="50px"></dx:GridViewDataColumn>
    <dx:GridViewDataColumn FieldName="ENDAREA" Caption="交易金额区间(结束)" VisibleIndex="3" Width="50px"></dx:GridViewDataColumn>
    <dx:GridViewDataColumn FieldName="PUSHMONEY" Caption="收取佣金(元/单笔)" VisibleIndex="4" Width="50px"></dx:GridViewDataColumn>
    <dx:GridViewDataComboBoxColumn FieldName="GETISFLAG" Caption="是否返回佣金" VisibleIndex="5" Width="30px">
    <PropertiesComboBox>
    <Items>
    <dx:ListEditItem Text="不返回" Value="0" />
    <dx:ListEditItem Text="返回" Value="1" />
    </Items>
    </PropertiesComboBox>
    </dx:GridViewDataComboBoxColumn>
    <dx:GridViewDataColumn FieldName="PUSHEXPRESS" Caption="返回佣金公式" VisibleIndex="6" ></dx:GridViewDataColumn>
    <%--<dx:GridViewDataColumn FieldName="ISVALID" Caption="是否有效" VisibleIndex="7" Width="5px"></dx:GridViewDataColumn>--%>
    <dx:GridViewDataCheckColumn FieldName="ISVALID" Caption="是否有效" VisibleIndex="7" Width="5px"></dx:GridViewDataCheckColumn>
    <dx:GridViewDataColumn FieldName="TREMARK" Caption="备注" VisibleIndex="8" Visible="false" Width="5px"></dx:GridViewDataColumn>
    <dx:GridViewCommandColumn ShowEditButton="true" ShowInCustomizationForm="true" ShowNewButtonInHeader="True" VisibleIndex="9" Width="20px" >
    <EditButton Text="修 改"></EditButton>
    <%--<NewButton Text ="新 增" >
    <Image SpriteProperties-CssClass="btn btn-xs btn-success" Width="100%">
    
    </Image>
    
    </NewButton>--%>
    <%-- <EditButton Text="修改"></EditButton>
    <UpdateButton Text="确认"></UpdateButton>
    <CancelButton Text="取消"></CancelButton>--%>
    </dx:GridViewCommandColumn>
    </Columns>
    <Templates>
    
    <EditForm>
    <div class="container-fluid" style="padding-bottom: 20px;">
    <div class="row">
    <div class="col-sm-12">
    <hr />
    </div>
    <div class="col-sm-6">
    
    <div class="form-group">
    <label>交易金额区间(起始)</label>
    <dx:ASPxSpinEdit ID="SE_BEGINAREA" runat="server" Number='<%# Eval("BEGINAREA") !=null ? decimal.Parse(Eval("BEGINAREA").ToString()) : 0%>' MinValue="0" NumberType="Float" Width="100%">
    </dx:ASPxSpinEdit>
    </div>
    </div>
    <div class="col-sm-6">
    <div class="form-group">
    <label>交易金额区间(结束)</label>
    <dx:ASPxSpinEdit ID="SE_ENDAREA" runat="server" Number='<%# Eval("ENDAREA") !=null ? decimal.Parse(Eval("ENDAREA").ToString()) : 0%>' MinValue="0" NumberType="Float" Width="100%">
    </dx:ASPxSpinEdit>
    </div>
    </div>
    <div class="col-sm-12">
    <div class="form-group">
    <label>收取佣金(元/单笔)</label>
    <dx:ASPxSpinEdit ID="SE_PUSHMONEY" runat="server" Number='<%# Eval("PUSHMONEY") !=null ? decimal.Parse(Eval("PUSHMONEY").ToString()) : 0%>' MinValue="0" NumberType="Float" Width="100%">
    </dx:ASPxSpinEdit>
    </div>
    </div>
    <div class="col-sm-8">
    <div class="form-group">
    <label>是否返回佣金</label>
    <dx:ASPxComboBox ID="CB_GETISFLAG" runat="server" ValueType="System.String" Width="100%" SelectedIndex='<%# Eval("GETISFLAG") != null? Eval("GETISFLAG").ToString() == "1" ? 1 : 0 : 0%>'>
    <Items>
    <dx:ListEditItem Text="不返回" Value="0" />
    <dx:ListEditItem Text="返回" Value="1" />
    </Items>
    </dx:ASPxComboBox>
    </div>
    </div>
    <div class="col-sm-4">
    <label></label>
    <dx:ASPxCheckBox ID="CHEKB_ISVALID" runat="server" Width="100%" Text="是否有效" Checked='<%# Eval("ISVALID") != null ? Eval("ISVALID").ToString() == "1" ? true : false : true %>'>
    </dx:ASPxCheckBox>
    </div>
    <div class="col-sm-12">
    <div class="form-group">
    <label>返回佣金公式</label>
    <dx:ASPxMemo ID="TXT_PUSHEXPRESS" runat="server" Text='<%# Eval("PUSHEXPRESS")%>' Width="100%" Height="72px">
    </dx:ASPxMemo>
    </div>
    <div class="form-group">
    <label>备注</label>
    <dx:ASPxMemo ID="TXT_TREMARK" runat="server" Text='<%# Eval("TREMARK")%>' Width="100%" Height="72px">
    </dx:ASPxMemo>
    </div>
    </div>
    <div class="col-sm-12">
    <hr />
    </div>
    
    <div class="col-sm-3 col-sm-offset-2">
    <%--<dx:ASPxGridViewTemplateReplacement ID="UpdateButton" ReplacementType="EditFormUpdateButton"
    runat="server">
    
    </dx:ASPxGridViewTemplateReplacement>--%>
    <dx:ASPxButton ID="UpdateButton" runat="server" Text="更 新" CssClass="btn-success" Width="100%" AutoPostBack="false">
    <ClientSideEvents Click="function(s,e){grid.UpdateEdit();}"></ClientSideEvents>
    </dx:ASPxButton>
    </div>
    <div class="col-sm-3 col-sm-offset-2">
    <%-- <dx:ASPxGridViewTemplateReplacement ID="CancelButton" ReplacementType="EditFormCancelButton"
    runat="server"></dx:ASPxGridViewTemplateReplacement>--%>
    <dx:ASPxButton ID="CancelButton" runat="server" Text="取 消" CssClass="btn-default" Width="100%" AutoPostBack="false">
    <ClientSideEvents Click="function(s,e){grid.CancelEdit();}"></ClientSideEvents>
    </dx:ASPxButton>
    </div>
    </div>
    </div>
    </EditForm>
    </Templates>
    </dx:ASPxGridView>

    //后台代码(实现数据绑定操作及赋值等)

    第一步:首先要定义一个自定义的方法-----用于获取到gridview中的编辑模板中的需要修改新增的控件名( 控件的id),方法如下

    protected object GetControlValue(string controlname,ASPxEditBase editBase)
    {
    editBase = ASPxGridView.FindEditFormTemplateControl(controlname) as ASPxEditBase;
    return editBase.Value;
    }

    获取编辑模板中的控件名:获取编辑模板中的控件名

    第二步:写新增、修改的方法(写在gridview自带的新增修改事件中),就以修改为例:

    protected void ASPxGridView_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
    int TPUSHMONEY_ID = Convert.ToInt32(e.Keys["TPUSHMONEY_ID"].ToString()); //拥金配置表id

    //ASPxSpinEdit SE_BEGINAREA = ASPxGridView.FindEditFormTemplateControl("SE_BEGINAREA") as ASPxSpinEdit;
    //Convert.ToDecimal(e.NewValues["BEGINAREA"] == null ? "" : e.NewValues["BEGINAREA"].ToString());
    decimal BEGINAREA = Convert.ToDecimal(GetControlValue("SE_BEGINAREA", spinEdit)); //交易金额区间(起始)
    decimal ENDAREA = Convert.ToDecimal(GetControlValue("SE_ENDAREA", spinEdit)); //交易金额区间(结束)
    decimal PUSHMONEY = Convert.ToDecimal(GetControlValue("SE_PUSHMONEY", spinEdit)); //收取佣金(元/单笔)
    int GETISFLAG = Convert.ToInt32(GetControlValue("CB_GETISFLAG", comboBox)); //是否返回佣金
    String PUSHEXPRESS = GetControlValue("TXT_PUSHEXPRESS", txtMemo).ToString(); //返回佣金公式
    int ISVALID = Convert.ToInt32(GetControlValue("CHEKB_ISVALID", checkBox)); //是否有效
    String TREMARK = GetControlValue("TXT_TREMARK", txtMemo).ToString(); //备注
    if (plateformmanagebll.UpdateCommSetting(TPUSHMONEY_ID,BEGINAREA, ENDAREA, PUSHMONEY, GETISFLAG, PUSHEXPRESS, ISVALID, TREMARK) > 0)
    {
    SpanHelper.AspxGridViewEdit(sender, 1, "恭喜!佣金公式修改成功!");
    e.Cancel = true;
    this.ASPxGridView.CancelEdit();
    showPlatmoneyList();
    }
    }

    模板编辑修改事件代码图:模板编辑修改事件代码图

    我还是会相信,星星会说话,石头会开花,穿过夏天的栅栏和冬天的风雪过后,你终会抵达。
  • 相关阅读:
    九章强化最后一章
    强化第一章
    双指针
    数据结构强化1
    动态规划强化
    动态规划
    selenium上传文件,怎么操作
    在python 3.6的eclipse中,导入from lxml import etree老是提示,Unresolved import:etree的错误
    在python 3.6下用pip 安装第三方库,比如pip install requests,老是报错 Fatal error in launcher: Unable to create process using '"'
    python3 + selenium + eclipse 中报错:'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
  • 原文地址:https://www.cnblogs.com/dfxyw/p/5080068.html
Copyright © 2020-2023  润新知