This is a migrated thread and some comments may be shown as answers.

[Solved] Disable Buttons

1 Answer 376 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SDI
Top achievements
Rank 1
SDI asked on 13 Feb 2013, 03:34 AM
I have a master table with its own server-side datasource. If you click edit the edit form comes up and display some textboxes to edit and a grid that has an edit column on it. the master also has a couple buttons for Update/Insert and a Cancel. These buttons work for the master datasource only. So the user clicks on the edit column for the row in the child grid and it has a edit form too that opens. This has its own Update/Insert and Cancel buttons. I need to disable the Master grid image buttons for Update/insert and Delete, then re-enable when the user is out of Edit mode on the child grid.


<%-- Edit form master event template --%>
                                    <EditFormSettings EditFormType="Template">
                                        <FormTemplate>
                                            <div class="data-container">
                                                <fieldset id="FieldsetEventMasterEdit" runat="server" style="width: 97%; height: 110px; margin: 5px; background-color: #FFFFCC;" class="ui-widget ui-widget-content ui-corner-all">
                                                    <div style="float: left;">
                                                        <asp:Label runat="server"><b>* denotes required field</b></asp:Label>
                                                    </div>
                                                    <div style="float: right;">
                                                        <asp:Table runat="server">
                                                            <asp:TableRow>
                                                                <asp:TableCell>
                                                                    <telerik:RadButton ID="RadButtonUpdateMasterEvent" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>' runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>' UseSubmitBehavior="false" />
                                                                </asp:TableCell>
                                                                <asp:TableCell>
                                                                    <telerik:RadButton ID="RadButtonCancelMasterEvent" Text="Close" runat="server" CausesValidation="False" CommandName="Cancel" UseSubmitBehavior="false" />
                                                                </asp:TableCell></asp:TableRow>
                                                        </asp:Table>


the two buttons "RadButtonUpdate..." and "RadButtonCancel..." should be disabled when...

<telerik:RadGrid runat="server" ID="RadGridEventSub" Height="100%" Width="100%" AllowMultiRowSelection="false" AutoGenerateColumns="false" OnItemCommand="RadGridEventSub_ItemCommand" OnDeleteCommand="RadGridEventSub_DeleteCommand" OnInsertCommand="RadGridEventSub_InsertCommand" OnUpdateCommand="RadGridEventSub_UpdateCommand" OnNeedDataSource="RadGridEventSub_NeedDataSource"
                                                    OnItemDataBound="RadGridEventSub_ItemDataBound" OnItemCreated="RadGridEventSub_ItemCreated" AllowAutomaticUpdates="false" AllowAutomaticInserts="false">
                                                    <MasterTableView CommandItemDisplay="Top" NoMasterRecordsText="There are no events to display..." AllowAutomaticInserts="false" AllowAutomaticUpdates="false" DataKeyNames="EventMasterId, EventSubId, GroupId, Name, EventTypeId" EditMode="EditForms">
                                                        <CommandItemSettings AddNewRecordText="Add a new sub event" ShowRefreshButton="false" />
                                                        <Columns>
                                                            <%-- this is the Pencil column for editing the record --%>
                                                            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" ItemStyle-Width="5%" ItemStyle-HorizontalAlign="Center">
                                                                <ItemStyle CssClass="GridRecordButton" />
                                                            </telerik:GridEditCommandColumn>

...the grid (RadGridEventSub) above goes into edit mode. RadGridEventSub is part of the FormTemplate.

Can you explain how to achieve this? thanks!

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 13 Feb 2013, 05:47 AM
Hi,

Try the following code to achieve your scenario.
C#:
protected void RadGridEventSub_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.EditCommandName)
        {
            RadGrid grid = (RadGrid)sender;
            GridEditFormItem item = (GridEditFormItem)grid.NamingContainer;
            RadButton update = (RadButton)item.FindControl("RadButtonUpdateMasterEvent");
            update.Enabled = false;
            RadButton cancel = (RadButton)item.FindControl("RadButtonCancelMasterEvent");
            cancel.Enabled = false;
        }
        if (e.CommandName == RadGrid.UpdateCommandName ||e.CommandName==RadGrid.CancelCommandName)
        {
            RadGrid grid = (RadGrid)sender;
            GridEditFormItem item = (GridEditFormItem)grid.NamingContainer;
            RadButton update = (RadButton)item.FindControl("RadButtonUpdateMasterEvent");
            update.Enabled = true;
            RadButton cancel = (RadButton)item.FindControl("RadButtonCancelMasterEvent");
            cancel.Enabled = true;
        }
}

Thanks,
Shinu
Tags
Grid
Asked by
SDI
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or