Module d=正确; } //获取任何现有Sku大小 var ExistingSkuSize=skusizeinfo.GetSkuSizeInfo(GetSkuID(),SizeID); //更新Sku大小 如果(!isChecked&&ExistingSkuSiz

Module d=正确; } //获取任何现有Sku大小 var ExistingSkuSize=skusizeinfo.GetSkuSizeInfo(GetSkuID(),SizeID); //更新Sku大小 如果(!isChecked&&ExistingSkuSiz,module,many-to-many,kentico,Module,Many To Many,Kentico,d=正确; } //获取任何现有Sku大小 var ExistingSkuSize=skusizeinfo.GetSkuSizeInfo(GetSkuID(),SizeID); //更新Sku大小 如果(!isChecked&&ExistingSkuSize!=null) { //删除现有的,因为未选中 ExistingSkuSize.Delete(); } else if(isChecked&&ExistingSkuSize==null) { //创建新的,因为它不存在 SkuSizeInfo

d=正确; } //获取任何现有Sku大小 var ExistingSkuSize=skusizeinfo.GetSkuSizeInfo(GetSkuID(),SizeID); //更新Sku大小 如果(!isChecked&&ExistingSkuSize!=null) { //删除现有的,因为未选中 ExistingSkuSize.Delete(); } else if(isChecked&&ExistingSkuSize==null) { //创建新的,因为它不存在 SkuSizeInfo newSkuSize=新SkuSizeInfo(); newskuize.SkuID=GetSkuID(); newskuize.SizeID=SizeID; newskuize.Upcharge=Upcharge; newSkuSize.VendorUpcharge=VendorUpcharge; newSkuSize.SkuSizeGuid=Guid.NewGuid(); newSkuSize.SkuSizeLastModified=DateTime.Now; newskuize.Insert(); } 否则,如果(已检查&(ExistingSkuSize.Upcharge!=Upcharge | | ExistingSkuSize.VendorUpcharge!=VendorUpcharge)) { //只需更新升级费用 现有SKUSIZE.Upcharge=Upcharge; ExistingSkuSize.VendorUpcharge=VendorUpcharge; ExistingSkuSize.Update(); } }捕获(例外情况除外) { erroroccurrent=true; EventLogProvider.LogException(“ProductSizes”,“UPDATEERROR”,ex,additionalMessage:string.Format(“无法设置/更新SkuID{0}的Sku大小,这可能是因为网格已更改。”,GetSkuID()); } } 如果(发生错误) { AddWarning(“保存时某些项目发生错误,请检查事件日志。”); }否则 { 添加确认(“产品尺寸更新”); //强制刷新,否则会出错 重定向(HttpContext.Current.Request.Url.PathAndQuery); } } }
#2似乎是最好的方法,除了扩展器之外,我所有的东西都在这一点上工作。现在正在处理这一部分。再看一眼,我现在想起来我无法覆盖网格上的save函数,所以我必须按照#4的路线,正常使用UniGrid(并返回一个列值控件),这是因为我需要在标题中添加我自己的“save”按钮。这是ASCX和代码隐藏块,可以使用!在本例中,我有一个带有复选框的“大小”的UniGrid,以及两个文本框值,它们可以从网格中填充并保存。
// ASCX
<!-- DO NOT Arranged or add to the columns without adjusting the back end code, as it references by index -->
    <div class="GridContent">
        <cms:UniGrid EnableTheming="true" ShowActionsMenu="false" ShowActionsLabel="false" ShowExportMenu="false" ShowObjectMenu="false" runat="server" ID="gridSizes" OrderBy="enabled desc, SizeOrder" AllColumns="SizeID, Enabled, SizeDisplayName, PriceAdjustment, Upcharge, VendorUpcharge" ApplyPageSize="false" PageSize="##ALL##">
            <GridActions Enabled="false" />
            <GridColumns>
                <ug:Column runat="server" Source="SizeID" Caption="SizeID" CssClass="hidden" AllowSorting="false" />
                <ug:Column runat="server" Source="Enabled" Caption="Enabled" ExternalSourceName="Enabled" AllowSorting="false" />
                <ug:Column runat="server" Source="SizeDisplayName" CssClass="DisplayName" Caption="Size Display Name" AllowSorting="false" />
                <ug:Column runat="server" Source="Upcharge" Caption="Upcharge" ExternalSourceName="Upcharge" AllowSorting="false" />
                <ug:Column runat="server" Source="VendorUpcharge" Caption="Vendor Upcharge" ExternalSourceName="VendorUpcharge" AllowSorting="false" />
            </GridColumns>
            <PagerConfig  ShowPageSize="false" ShowDirectPageControl="false" PageSizeOptions="##ALL##" runat="server" Visible="false" />
        </cms:UniGrid>
    </div>
    <cms:FormSubmitButton runat="server" ID="btnSaveItems" OnClick="btnSave_Click" />

// Code Behind
private void SetSizesTable()
    {
        QueryDataParameters parameters = new QueryDataParameters();
        parameters.Add("@SkuID", GetSkuID());
        int totalRecords = 0;
        DataSet ds = YourDataCallHere;
        gridSizes.DataSource = ds;
        gridSizes.OnExternalDataBound += GridSizes_OnExternalDataBound;
        gridSizes.DataBind();
    }

private object GridSizes_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        // Replace the Enabled and Upcharge with actual controls, this way the user can adjust them
        // and then those values retrieved when saved.
        switch(sourceName.ToLower())
        {
            case "enabled":
                var enabled = ValidationHelper.GetBoolean(parameter, false);
                CheckBox cbxEnabled = new CheckBox();
                cbxEnabled.Checked = enabled;
                cbxEnabled.TabIndex = 100;
                return cbxEnabled;
            case "upcharge":
            case "vendorupcharge":
                var price = ValidationHelper.GetDecimal(parameter, 0);
                CMSTextBox txtBox = new CMSTextBox();
                txtBox.Text = price.ToString("F2");
                txtBox.TabIndex = 1000;
                return txtBox;
            default:
                return parameter;
        }
    }

// Save logic here
protected void btnSave_Click(object sender, EventArgs e)
    {
        // Loop through the actual control rows so we can retrieve the values and update.
        ControlFinder<GridViewRow> GridViewRowFinder = new ControlFinder<GridViewRow>();
        GridViewRowFinder.FindChildControlsRecursive(gridSizes);

        bool ErrorOccurred = false;

        // Skip the first and last as they are the header / action rows
        foreach (GridViewRow RowItem in GridViewRowFinder.FoundControls.Skip(1).Take(GridViewRowFinder.FoundControls.Count()-2))
        {
            try
            {
                // Retrieve the values from the controls.  These are based on the Cell index so any modification to the
                // UniGrid may break this and need updating!
                int SizeID = ValidationHelper.GetInteger(((LiteralControl)RowItem.Cells[1].Controls[0]).Text, -1);
                bool isChecked = ((CheckBox)RowItem.Cells[2].Controls[0]).Checked;
                decimal Upcharge = ValidationHelper.GetDecimal(((CMSTextBox)RowItem.Cells[4].Controls[0]).Text, 0);
                decimal VendorUpcharge = ValidationHelper.GetDecimal(((CMSTextBox)RowItem.Cells[5].Controls[0]).Text, 0);
                if (Upcharge > 0 || VendorUpcharge > 0)
                {
                    isChecked = true;
                }
                // Grab any existing Sku Size
                var ExistingSkuSize = SkuSizeInfoProvider.GetSkuSizeInfo(GetSkuID(), SizeID);

                // Update the Sku Size
                if (!isChecked && ExistingSkuSize != null)
                {
                    // Delete existing since unchecked
                    ExistingSkuSize.Delete();
                }
                else if (isChecked && ExistingSkuSize == null)
                {
                    // Create new one since it does not exist
                    SkuSizeInfo newSkuSize = new SkuSizeInfo();
                    newSkuSize.SkuID = GetSkuID();
                    newSkuSize.SizeID = SizeID;
                    newSkuSize.Upcharge = Upcharge;
                    newSkuSize.VendorUpcharge = VendorUpcharge;
                    newSkuSize.SkuSizeGuid = Guid.NewGuid();
                    newSkuSize.SkuSizeLastModified = DateTime.Now;
                    newSkuSize.Insert();
                }
                else if (isChecked && (ExistingSkuSize.Upcharge != Upcharge || ExistingSkuSize.VendorUpcharge != VendorUpcharge))
                {
                    // Just update the upcharge
                    ExistingSkuSize.Upcharge = Upcharge;
                    ExistingSkuSize.VendorUpcharge = VendorUpcharge;
                    ExistingSkuSize.Update();
                }
            } catch(Exception ex)
            {
                ErrorOccurred = true;
                EventLogProvider.LogException("ProductSizes", "UPDATEERROR", ex, additionalMessage: string.Format("Unable to Set/Update the Sku Size for SkuID {0}, this could be because the grid was altered.", GetSkuID()));
            }
        }

        if(ErrorOccurred)
        {
            AddWarning("An error occured on some items while saving, please check the Event Log.");
        } else
        {
            AddConfirmation("Product Sizes Updated.");
            // Force refresh as otherwise it messes up
            URLHelper.Redirect(HttpContext.Current.Request.Url.PathAndQuery);
        }

    }
}