FindControl return null for RadEditor

99封情书 提交于 2019-12-11 13:19:54

问题


I have the following RadGrid below. I am trying to access the RadEditor when I edit and set visible to false the following way but getting an error that it is null:

  protected void ItemCommand(object sender, GridCommandEventArgs e)
  {

        if (e.CommandName == "Edit")
        {

            var gridItem = e.Item as GridEditableItem;
            if ("ActionItems".Equals(e.Item.OwnerTableView.Name))
            {                   
                GridEditableItem editItem = e.Item as GridEditableItem;

                RadEditor radEditor = editItem.FindControl("LimitEdit") as RadEditor;
                radEditor.Visible = false; // get error message saying radEditor is null.         


            }
        }
  }




       <telerik:RadGrid HeaderStyle-ForeColor="White" ID="SupportItemGrid" runat="server" CellSpacing="0" DataSourceID="SupportItemSource"
        GridLines="None" OnInsertCommand="ItemInsert" OnItemCommand="ItemCommand" Skin="Metro" OnDeleteCommand="RadGrid1_DeleteCommand"
        OnDataBound="SupportItemGrid_DataBound" OnItemDataBound="ItemDatabound" AllowSorting="true" AllowAutomaticUpdates="true">
        <ValidationSettings EnableValidation="True" CommandsToValidate="Insert"></ValidationSettings>
        <MasterTableView AutoGenerateColumns="False" DataKeyNames="CompanyId,ItemId" DataSourceID="ActionItemSource"
            AllowAutomaticInserts="True" AllowAutomaticUpdates="True" CommandItemDisplay="Top" AllowSorting="true"
            Name="ActionItems" AllowPaging="True" PageSize="20" ExpandCollapseColumn-HeaderText="Comments"
            ExpandCollapseColumn-UniqueName="Comments" HierarchyLoadMode="Client">
            <HeaderStyle HorizontalAlign="Center" ForeColor="White"></HeaderStyle>
            <CommandItemSettings AddNewRecordText="Add New Support Item" ShowExportToExcelButton="true"></CommandItemSettings>
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
            </EditFormSettings>
            <DetailTables>
                <telerik:GridTableView runat="server" AllowAutomaticInserts="True" DataKeyNames="CommentId"
                    Name="Comments" DataSourceID="CommentSource" CommandItemDisplay="Top" AutoGenerateColumns="False"
                    NoDetailRecordsText="No Comments To Display">
                    <ParentTableRelation>
                        <telerik:GridRelationFields DetailKeyField="CompanyId" MasterKeyField="CompanyId" />
                        <telerik:GridRelationFields DetailKeyField="ItemId" MasterKeyField="ItemId" />
                    </ParentTableRelation>
                    <CommandItemSettings ExportToPdfText="Export to PDF" AddNewRecordText="Add New Comment" />
                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                        <HeaderStyle Width="20px" />
                    </ExpandCollapseColumn>
                    <EditFormSettings>
                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                        </EditColumn>
                    </EditFormSettings>
                    <Columns>
                        <telerik:GridTemplateColumn DataField="Comment" FilterControlAltText="Filter Comment column"
                            HeaderText="Comment" SortExpression="Comment" UniqueName="Comment">
                            <EditItemTemplate>
                                <asp:TextBox ID="DescriptionTextBox" runat="server" TextMode="MultiLine" Height="100px"
                                    Width="400" Text='<%# Bind("Comment") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="CommentLabel" runat="server" Text='<%# Eval("Comment") %>'></asp:Label>
                            </ItemTemplate>

                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="UserName" DataType="System.String" FilterControlAltText="Filter UserName column"
                            HeaderText="User Name" SortExpression="UserName" UniqueName="UserName" ReadOnly="True">
                            <HeaderStyle Width="150"></HeaderStyle>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="DateEntered" DataType="System.DateTime" FilterControlAltText="Filter DateEntered column"
                            HeaderText="Date Entered" SortExpression="DateEntered" UniqueName="DateEntered"
                            ReadOnly="True">
                            <HeaderStyle Width="150"></HeaderStyle>
                        </telerik:GridBoundColumn>

                        <telerik:GridTemplateColumn UniqueName="DeleteDetail" Visible="false">
                            <ItemTemplate>
                                <telerik:RadButton ID="RemoveButton" runat="server" CommandName="Delete" Text="Delete" Width="75px"></telerik:RadButton>
                            </ItemTemplate>
                            <HeaderStyle Width="75"></HeaderStyle>
                        </telerik:GridTemplateColumn>

                    </Columns>
                </telerik:GridTableView>
            </DetailTables>
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridDropDownColumn DataSourceID="SitesDS" ListTextField="SiteName"
                    ListValueField="SiteId" UniqueName="SiteId" SortExpression="SiteId"
                    HeaderText="Site" DataField="SiteId" DropDownControlType="DropDownList" AllowVirtualScrolling="true"
                    ShowMoreResultsBox="true" ItemsPerRequest="10">
                </telerik:GridDropDownColumn>
                <telerik:GridBoundColumn DataField="DateEntered" FilterControlAltText="Filter DateEntered column"
                    HeaderText="Date Entered" SortExpression="DateEntered" UniqueName="DateEntered"
                    DataType="System.DateTime">
                    <HeaderStyle Width="85"></HeaderStyle>
                </telerik:GridBoundColumn>
                <telerik:GridDropDownColumn DataSourceID="ItemTypeSource" ListTextField="ItemType"
                    ListValueField="ItemTypeId" UniqueName="ItemTypeId" SortExpression="ItemTypeId"
                    HeaderText="Type" DataField="ItemTypeId" DropDownControlType="DropDownList" AllowVirtualScrolling="true"
                    ShowMoreResultsBox="true" ItemsPerRequest="10">

                    <HeaderStyle Width="120"></HeaderStyle>
                </telerik:GridDropDownColumn>

                <telerik:GridTemplateColumn DataField="Description" FilterControlAltText="Filter Description column"
                    HeaderText="Description" SortExpression="Description" UniqueName="Description">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtDescription" UniqueName="txtDescription" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>

                        <telerik:RadEditor  StripFormattingOnPaste="MSWord" ID="LimitEdit" runat="server" Content='<%# Bind("Description") %>'
                            Skin="Windows7">
                        </telerik:RadEditor>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </telerik:GridTemplateColumn>   


                <telerik:GridButtonColumn ConfirmText="Delete?" ConfirmDialogType="RadWindow" HeaderText="Delete" SortExpression="DeleteMain" UniqueName="DeleteMain"
                    Display="false" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />

            </Columns>
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
            </EditFormSettings>
            <EditItemStyle HorizontalAlign="Left" />
        </MasterTableView>
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
        </HeaderContextMenu>
    </telerik:RadGrid>

回答1:


Although you're not using a repeater, you're probably hitting the same issue as described & solved in this SO Question - How to FindControls in repeater control?

That is, until the RadGrid is bound, the controls don't exist.



来源:https://stackoverflow.com/questions/35436413/findcontrol-return-null-for-radeditor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!