Checkbox uses changeEditor, but need to call other code

2 posts, 0 answers
  1. Jeremy Yoder
    Jeremy Yoder avatar
    131 posts
    Member since:
    Dec 2009

    Posted 05 Apr Link to this post

     

    Checkboxes in a batch grid require an extra click to put them into Edit mode, but that's fixed with this code I got on this forum...

    function changeEditor(sender) {
        var grd = GetControlRAD("grdPODetails");
        var batchManager = grd.get_batchEditingManager();
        batchManager.openCellForEdit(sender.parentElement.parentElement);
        sender.checked = !sender.checked;
    }

    <telerik:RadGrid ID="grdPODetails" runat="server" AllowSorting="True" AutoGenerateColumns="False" Skin="Office2010Blue" GridLines="None">
        <HeaderContextMenu EnableAutoScroll="True">
        </HeaderContextMenu>
        <MasterTableView CommandItemDisplay="Top" EditMode="Batch" InsertItemDisplay="Bottom"
                ClientDataKeyNames="PurchaseOrderDetailKey"
                DataKeyNames="PurchaseOrderDetailKey">
            <BatchEditingSettings EditType="Cell" OpenEditingEvent="Click" />
            <CommandItemSettings ShowRefreshButton="False" ShowSaveChangesButton="true" ShowCancelChangesButton="true" />
            <NoRecordsTemplate>
                No detail lines to display.
            </NoRecordsTemplate>
            <Columns>
     
                <telerik:GridTemplateColumn DataField="PrintOnPurchaseOrder" HeaderText="Print" UniqueName="PrintOnPurchaseOrder" DataType="System.Boolean">
                    <HeaderStyle Width="40px" />
                    <ItemStyle Width="40px" />
                    <ItemTemplate>
                        <input id="chkPrint" type="checkbox" checked='<%# Eval("PrintOnPurchaseOrder") %>' onclick="changeEditor(this);" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:CheckBox ID="chkPrint" runat="server" Checked='<%# Bind("PrintOnPurchaseOrder") %>' />
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn DataField="PostToGeneralLedger" HeaderText="Post" UniqueName="PostToGeneralLedger" DataType="System.Boolean">
                    <HeaderStyle Width="40px" />
                    <ItemStyle Width="40px" />
                    <ItemTemplate>
                        <input id="chkPost" type="checkbox" checked='<%# Eval("PostToGeneralLedger") %>' onclick="changeEditor(this);" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:CheckBox ID="chkPost" runat="server" Checked='<%# Bind("PostToGeneralLedger") %>' />
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
     
                <telerik:GridTemplateColumn DataField="UnitDescription" UniqueName="UnitDescription" HeaderText="Unit Desc" DataType="System.String">
                    <ItemTemplate>
                        <asp:Label ID="lblUnitDescription" runat="server"
                            Text='<%# Eval("UnitDescription") %>'>
                        </asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadTextBox ID="txtUnitDescription" runat="server" MaxLength="10" Width="100%"
                        Text='<%# Bind("UnitDescription") %>' >
                        </telerik:RadTextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
     
            </Columns>
        </MasterTableView>
        <ClientSettings AllowKeyboardNavigation="true">
            <Selecting AllowRowSelect="True" />
            <ClientEvents/>
        </ClientSettings>
    </telerik:RadGrid>

     

    A breakpoint in changeEditor shows it's only called once, to put it in edit mode. But the first time you click it (and every time following if you keep clicking it while still in edit mode) I need to handle that event. For instance, in this grid, if I check the checkbox in the 2nd column, how can I set column "UnitDescription" in the same row to "A", but if I uncheck the checkbox (while still in EditMode) it sets UnitDescription" to "B"?

    I tried putting an event handler on the checkbox within EditItemTemplate, but that didn't work... or I did it wrong. It's almost like when it opens in edit mode, a new checkbox is created on the fly. But I can't figure out where it is or how to grab its events. Please help.

     

  2. Kostadin
    Admin
    Kostadin avatar
    1713 posts

    Posted 08 Apr Link to this post

    Hi Jeremy,

    A possible solution is to update the cell value by calling changeCellValue method and pass the cell element and the new value. Please check out the following help article for more information. Additionally you can examine the following how to article for more details.

    Regards,
    Kostadin
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top