0

Stackoverflow に関する初めての質問

ASP.NET C# グリッドビュー

私の質問はこれです

コマンド フィールド テンプレートに、行を編集モードに切り替えてもフィールドの 1 つに異なるコンテンツを表示するカスタムの [編集] ボタンを配置するにはどうすればよいですか。

コマンド列用のテンプレート フィールドがあります。ロジックには rowdatabound イベントを使用します。

 <asp:templatefield itemstyle-width="300px">
    <itemtemplate>
        <asp:Literal ID="label2" runat="server" Text='<%# System.Net.WebUtility.HtmlDecode(Eval("translation").ToString()) %>'></asp:Literal>
    </itemtemplate>
    <edititemtemplate>
        <cc1:myeditor ID="teHtml" startupInSourceOrwysiwyg="wysiwyg" type="lite" EnableViewState="false" runat="server" Text='<%# Bind("translation")%>' />
    </edititemtemplate>
</asp:templatefield>
    <asp:templatefield headertext="Command">
    <itemtemplate>
        <asp:LinkButton CommandName="Edit" Text="Edit" ID="btnEdit" runat="server"></asp:LinkButton>
        <asp:LinkButton CommandName="EditHtml" Text="EditHtml" ID="btnEditHtml" runat="server" ></asp:LinkButton>
    </itemtemplate>
    <edititemtemplate>
        <asp:LinkButton CommandName="Update" Text="Update" ID="btnUpdate" runat="server"></asp:LinkButton>
        <asp:LinkButton CommandName="Cancel" Text="Cancel" ID="btnCancel" runat="server"></asp:LinkButton>
    </edititemtemplate>
</asp:templatefield>

コード ビハインド - イベント

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
        {
            CkEditor editorInstance = (CkEditor)e.Row.FindControl("teHtml");

            string theTranslationText = editorInstance.Text;
            bool isHtmlModeSelected;

            isHtmlModeSelected = hfHtml.Value == "true" ? true : false;

            if (!(isHtmlModeSelected) || (someHtmlFoundInTranslation(theTranslationText)))
            {
                editorInstance.startupInSourceOrwysiwyg = "source";
                editorInstance.removeplugins = "toolbar";
            }
        }
    }

ありがとう

4

0 に答える 0