Re: Reviewing the CuteEditor Database example

  •  10-12-2008, 11:09 PM

    Re: Reviewing the CuteEditor Database example

    Hi jfeeney,
     
    In this example,you can click the save button of  editor to save the text.
    example:
     

    <%@ Page Language="C#" %>

    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!IsPostBack)
            {
                ArrayList values = new ArrayList();

                values.Add("Apple");
                values.Add("Orange");
                values.Add("Pear");
                values.Add("Banana");
                values.Add("Grape");

                // Set the DataSource of the Repeater.
                Repeater1.DataSource = values;
                Repeater1.DataBind();

            }

        }
        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "edit")
            {
                CuteEditor.Editor editor = (CuteEditor.Editor)e.Item.FindControl("editor1");
                editor.Visible = true;
            }

        }

        protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
        {
            CuteEditor.Editor editor = (CuteEditor.Editor)e.Item.FindControl("editor1");
            editor.PostBackCommand += new CommandEventHandler(editor_PostBackCommand);
        }

        void editor_PostBackCommand(object sender, CommandEventArgs e)
        {
            CuteEditor.Editor editor = (CuteEditor.Editor)sender;
            RepeaterItem item = null;
            for (Control c = editor; c != null; c = c.Parent)
            {
                if (c is RepeaterItem)
                {
                    item = (RepeaterItem)c;
                    break;
                }
            }
            Label label1 = (Label)item.FindControl("label1");
            if (e.CommandName == "Save")
            {
                label1.Text = editor.Text;
                editor.Visible = false;
            }

        }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand"
                    OnItemCreated="Repeater1_ItemCreated">
                    <ItemTemplate>
                        <asp:Label ID="label1" runat="server" Text='<%# Container.DataItem %>'></asp:Label>
                        <asp:Button ID="button1" runat="server" Text="Edit" CommandName="edit" />
                        <%-- <asp:Button ID=Save runat=server  Visible=false CommandName=Save Text=Save/>--%>
                        <CE:Editor ID="editor1" runat="server" Visible="false">
                        </CE:Editor>
                    </ItemTemplate>
                </asp:Repeater>
            </div>
        </form>
    </body>
    </html>

     
     
     
    Regards,
     
    Ken
View Complete Thread