从 GridButtonColumn 启动编辑表单

发布于 2024-12-12 21:37:10 字数 2444 浏览 0 评论 0原文

我有一个类定义了一个分层 RadGrid,我将在应用程序范围内使用它。这个网格有很多列,所以这对我来说是最好的实现,因为我将覆盖基于网格的 om 实现的特定特征。

网格将根据用户的访问级别以不同的方式运行。在“基本用户级别”,他们将在父网格上添加新项目/编辑项目,并在子网格上具有编辑、拒绝(删除)、批准(更新)

功能。下一个级别将是“批准者”角色。他们不会在父网格上添加新项目/编辑项目,而只会在子网格上拒绝(编辑)。用户在拒绝项目时将在此角色中执行的编辑操作是,他们将被要求通过用户控件输入注释,该用户控件将在单击拒绝按钮时启动。我遇到的问题是,当使用 GridButtonColumn 作为触发事件时,自定义用户控件不会显示 DetailTableView.EditFormSettings。有什么想法吗? TIA

private void SubmittedBatchesRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    GridDataItem _dataItem = e.Item as GridDataItem;
    if (_dataItem == null) return;

    if (e.Item.OwnerTableView.Name == "SubmittedBatchesRadGrid_ChildGrid")
    {
        SetChildGridCommandColumns(sender, e);
        return;
    }

    if (_dataItem.KeyValues == "{}") { return; }

    SetMasterGridCommandColumns(sender, e, _dataItem);

}

private static void SetChildGridCommandColumns(object sender, GridItemEventArgs e)
{
    const string _jqueryCode = "if(!$find('{0}').confirm('{1}', event, '{2}'))return false;";
    const string _confirmText = "<p>Rejecting this adjustment will mean that you will have to also reject the batch when you are done processing these items.</p><p>Are you sure you want to reject this adjustment?</p>";
    ((ImageButton)(((GridEditableItem)e.Item)["PolicyEditRecord"].Controls[0])).ImageUrl = "/controls/styles/images/editpencil.png";
    ImageButton _btnReject = (ImageButton)((GridDataItem)e.Item)["DeleteTransaction"].Controls[0];

    _btnReject.CommandName = "Update";
    _btnReject.ImageUrl = "/controls/styles/images/decline.png";
    _btnReject.ToolTip = "Reject this item";
    //_btnReject.Attributes["onclick"] = string.Format(_jqueryCode, ((Control)sender).ClientID, _confirmText, "Reject Adjustment");
}

private void SubmittedBatchesRadGrid_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
    e.DetailTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
    e.DetailTableView.EditFormSettings.UserControlName = "/Controls/RejectedAdjustmentComment.ascx";
    e.DetailTableView.EditMode = GridEditMode.PopUp;

    e.DetailTableView.CommandItemSettings.ShowAddNewRecordButton = false;
    GridDataItem _dataItem = e.DetailTableView.ParentItem;
    e.DetailTableView.DataSource = AdjustmentAPI.GetAdjustmentsByBatch(Convert.ToInt32(_dataItem.GetDataKeyValue("BatchID").ToString()), PolicyClaimManualAdjustmentCode);
}

I have a class that defines a Hierarchical RadGrid that I will be using application wide. This grid has many column so this is the best implementation for me, as I will be overriding specific characteristics of the grid based om implementation.

The grid will function in a different manner based on the access level of the user. On a 'basic user level' they will have a Add New Item/Edit Item on the parent grid and Edit, Reject(delete), Approve(Update) on the Child Grid

The next level will be a 'Approver' role. They will NOT have Add New Item/Edit Item on the parent grid and will only have Reject(Edit) on the child. The edit action that the user will take in this role when rejecting an item is that they will be required to enter a comment through a user control that will be launched when the click the reject button. The problem that I am having is that the custom user control is not displaying for a DetailTableView.EditFormSettings when using a GridButtonColumn as the firing event. Any thoughts? TIA

private void SubmittedBatchesRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    GridDataItem _dataItem = e.Item as GridDataItem;
    if (_dataItem == null) return;

    if (e.Item.OwnerTableView.Name == "SubmittedBatchesRadGrid_ChildGrid")
    {
        SetChildGridCommandColumns(sender, e);
        return;
    }

    if (_dataItem.KeyValues == "{}") { return; }

    SetMasterGridCommandColumns(sender, e, _dataItem);

}

private static void SetChildGridCommandColumns(object sender, GridItemEventArgs e)
{
    const string _jqueryCode = "if(!$find('{0}').confirm('{1}', event, '{2}'))return false;";
    const string _confirmText = "<p>Rejecting this adjustment will mean that you will have to also reject the batch when you are done processing these items.</p><p>Are you sure you want to reject this adjustment?</p>";
    ((ImageButton)(((GridEditableItem)e.Item)["PolicyEditRecord"].Controls[0])).ImageUrl = "/controls/styles/images/editpencil.png";
    ImageButton _btnReject = (ImageButton)((GridDataItem)e.Item)["DeleteTransaction"].Controls[0];

    _btnReject.CommandName = "Update";
    _btnReject.ImageUrl = "/controls/styles/images/decline.png";
    _btnReject.ToolTip = "Reject this item";
    //_btnReject.Attributes["onclick"] = string.Format(_jqueryCode, ((Control)sender).ClientID, _confirmText, "Reject Adjustment");
}

private void SubmittedBatchesRadGrid_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
    e.DetailTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
    e.DetailTableView.EditFormSettings.UserControlName = "/Controls/RejectedAdjustmentComment.ascx";
    e.DetailTableView.EditMode = GridEditMode.PopUp;

    e.DetailTableView.CommandItemSettings.ShowAddNewRecordButton = false;
    GridDataItem _dataItem = e.DetailTableView.ParentItem;
    e.DetailTableView.DataSource = AdjustmentAPI.GetAdjustmentsByBatch(Convert.ToInt32(_dataItem.GetDataKeyValue("BatchID").ToString()), PolicyClaimManualAdjustmentCode);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩发小公举 2024-12-19 21:37:10

看起来您只需要使用 OnClientClick 代替,并返回确认对话框的值。

_btnReject.OnClientClick = "return confirm(\"Are you sure you?\");"

RadAjax 在确认对话框时有一个小怪癖,因此您可能需要使用它:

_btnReject.OnClientClick = "if (!confirm(\"Are you sure?\")) return false;"

It looks like you just need to use OnClientClick instead, and return the value of the confirm dialog.

_btnReject.OnClientClick = "return confirm(\"Are you sure you?\");"

RadAjax has a little quirk when it comes to confirm dialogs, so you may need to use this instead:

_btnReject.OnClientClick = "if (!confirm(\"Are you sure?\")) return false;"
旧梦荧光笔 2024-12-19 21:37:10

所以我想我会分享我的解决方案,以防其他人需要它。

我用编辑控件找错了树。尽管注释是 RadGrid 中数据集的一部分,但我不想编辑现有记录。我决定创建一个用户控件来处理该过程。 RadWindow 不直接采用 .ascx 页面,因此我从 .aspx 包装页面开始并在那里插入控件。然后我更改了 OnClientClick 事件以启动 RadWindow 加载新的 aspx 文件,并将我需要的参数传递给用户控件。用户控件将评论保存到数据库并更新记录状态,然后关闭。

我从上面修改了这一部分:

    private static void SetChildGridCommandColumns(object sender, GridItemEventArgs e)
    {
        ((ImageButton)(((GridEditableItem)e.Item)["PolicyEditRecord"].Controls[0])).ImageUrl = "/controls/styles/images/editpencil.png";
        ImageButton _btnReject = (ImageButton)((GridDataItem)e.Item)["DeleteTransaction"].Controls[0];
        int _manualAdjustmentId = Convert.ToInt32(((GridDataItem)e.Item)["ManualAdjustmentId"].Text);
        int _manualAdjustmentBatchId = Convert.ToInt32(((GridDataItem)e.Item)["ManualAdjustmentBatchId"].Text);

        _btnReject.ImageUrl = "/controls/styles/images/decline.png";
        _btnReject.ToolTip = "Reject this item";
        _btnReject.OnClientClick = String.Format("OpenRadWindow('/controls/RejectedAdjustmentComment.aspx?manualAdjustmentId={0}&manualAdjustmentBatchId={1}', 'CommentDialog');return false;", _manualAdjustmentId, _manualAdjustmentBatchId);
    }

    private void SubmittedBatchesRadGrid_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
    {
//I deleted this section
        e.DetailTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
        e.DetailTableView.EditFormSettings.UserControlName = "/Controls/RejectedAdjustmentComment.ascx";
        e.DetailTableView.EditMode = GridEditMode.PopUp;
//

        e.DetailTableView.CommandItemSettings.ShowAddNewRecordButton = false;
        GridDataItem _dataItem = e.DetailTableView.ParentItem;
        e.DetailTableView.DataSource = AdjustmentAPI.GetAdjustmentsByBatch(Convert.ToInt32(_dataItem.GetDataKeyValue("BatchID").ToString()), PolicyClaimManualAdjustmentCode);
    }

我将其添加到带有数据网格的页面中:

<telerik:RadWindowManager ID="SubmittedBatchesWindow" runat="server">
    <windows>
            <telerik:RadWindow ID="CommentDialog" runat="server" Title="Rejected Agjustment Comment Dialog"
                Height="350px" Width="440" Left="250px" ReloadOnShow="false" ShowContentDuringLoad="false"
                Modal="true" VisibleStatusbar="false" />
        </windows>
</telerik:RadWindowManager>

我创建了一个新的 aspx 文件并在其中插入了新的 ascx 控件

<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<uc:RejectedComment id="RejectionComment1" runat="server" />
</form>

我在 ascx 文件中添加了用于更新的代码、前端的 javascript

<script language ="javascript" type ="text/javascript" >   
    //<![CDATA[
    function GetRadWindow() {
        var oWindow = null;
        if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
        else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)

        return oWindow;
    }

    function CancelEdit() {
        GetRadWindow().close();
    }

    //]]>
</script>  

和最后但并非最不重要的一点是,在按钮单击事件中成功更新后关闭窗口;

Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "CancelEdit();", true);

我希望其他人发现这很有用。我花了几个小时在 Telerik 网站上寻找这个网站,一点一点地找到了它。

So I thought I would share my solution in case anyone else needs it.

I was barking up the wrong tree with the edit control. Even though a comment is part of the dataset in the RadGrid I don't want to edit the existing record. I decided to create a usercontrol to handle the process. The RadWindow does not take .ascx pages directly so I started with a .aspx wrapper page and inserted the control there. Then I changed the OnClientClick event to launch the RadWindow loading the new aspx file passing the parameters I needed to the usercontrol. The usercontrol saves the comment to the database and updates the record status and then closes.

I modified this section from above:

    private static void SetChildGridCommandColumns(object sender, GridItemEventArgs e)
    {
        ((ImageButton)(((GridEditableItem)e.Item)["PolicyEditRecord"].Controls[0])).ImageUrl = "/controls/styles/images/editpencil.png";
        ImageButton _btnReject = (ImageButton)((GridDataItem)e.Item)["DeleteTransaction"].Controls[0];
        int _manualAdjustmentId = Convert.ToInt32(((GridDataItem)e.Item)["ManualAdjustmentId"].Text);
        int _manualAdjustmentBatchId = Convert.ToInt32(((GridDataItem)e.Item)["ManualAdjustmentBatchId"].Text);

        _btnReject.ImageUrl = "/controls/styles/images/decline.png";
        _btnReject.ToolTip = "Reject this item";
        _btnReject.OnClientClick = String.Format("OpenRadWindow('/controls/RejectedAdjustmentComment.aspx?manualAdjustmentId={0}&manualAdjustmentBatchId={1}', 'CommentDialog');return false;", _manualAdjustmentId, _manualAdjustmentBatchId);
    }

    private void SubmittedBatchesRadGrid_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
    {
//I deleted this section
        e.DetailTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
        e.DetailTableView.EditFormSettings.UserControlName = "/Controls/RejectedAdjustmentComment.ascx";
        e.DetailTableView.EditMode = GridEditMode.PopUp;
//

        e.DetailTableView.CommandItemSettings.ShowAddNewRecordButton = false;
        GridDataItem _dataItem = e.DetailTableView.ParentItem;
        e.DetailTableView.DataSource = AdjustmentAPI.GetAdjustmentsByBatch(Convert.ToInt32(_dataItem.GetDataKeyValue("BatchID").ToString()), PolicyClaimManualAdjustmentCode);
    }

I added this to the page with the datagrid:

<telerik:RadWindowManager ID="SubmittedBatchesWindow" runat="server">
    <windows>
            <telerik:RadWindow ID="CommentDialog" runat="server" Title="Rejected Agjustment Comment Dialog"
                Height="350px" Width="440" Left="250px" ReloadOnShow="false" ShowContentDuringLoad="false"
                Modal="true" VisibleStatusbar="false" />
        </windows>
</telerik:RadWindowManager>

I created a new aspx file and inserted the new ascx control inside

<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<uc:RejectedComment id="RejectionComment1" runat="server" />
</form>

I added my code behind for the update in the ascx file, the javascript for the front end

<script language ="javascript" type ="text/javascript" >   
    //<![CDATA[
    function GetRadWindow() {
        var oWindow = null;
        if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
        else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)

        return oWindow;
    }

    function CancelEdit() {
        GetRadWindow().close();
    }

    //]]>
</script>  

and last but not least closing the window after a successful update in the button click event;

Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "CancelEdit();", true);

I hope someone else finds this useful. It took me several hours hunting the telerik site to find this piece by piece.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文