0

My first ever question on Stackoverflow

ASP.NET C# Gridview

My question is this

How can I have a custom Edit button in my command field template that will still switch the rows to edit mode but will show different content in one of the fields.

I have a template field for my command columns. I use the rowdatabound event for the logic.

 <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>

Code Behind - Event

    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";
            }
        }
    }

Thanks

Wazi
  • 11
  • 4

0 Answers0