Reviewing the CuteEditor Database example

Last post 10-13-2008, 10:18 AM by jfeeney. 4 replies.
Sort Posts: Previous Next
  •  10-10-2008, 7:57 PM 44803

    Reviewing the CuteEditor Database example

    In database-example, the database is attached to a datagrid and then as the item is selected CuteEditor Editor1.Text is equal to the text string that comes from the datagrid.
     
    Is it possible to go directly from the CuteEditor to the database with a DataBinding command (for example). I was playing around with trying to put the CuteEditor inside a Repeater...but that did not prove successful.
     
    I am setting up my program so that the database section has a DAL (Data Access Layer) and BLL (Business Logic Layer). Then I  have a ObjectDataSource looking at the BLL.
     
    After, playing around with this I have made the ASSUMPTION that it is not possible to directly attach CuteEditor to an ObjectDataSource. Is this assumption correct?
  •  10-11-2008, 8:15 AM 44815 in reply to 44803

    Re: Reviewing the CuteEditor Database example

    Hi jfeeney,
     
     
    please try this 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");
                Button Save = (Button)e.Item.FindControl("Save");
                Save.Visible = true;
                editor.Visible = true;
            }
            if (e.CommandName == "Save")
            {
                CuteEditor.Editor editor = (CuteEditor.Editor)e.Item.FindControl("editor1");
                Button Save = (Button)e.Item.FindControl("Save");
                Label label1 = (Label)e.Item.FindControl("label1");
                label1.Text = editor.Text;
                editor.Visible = false;
                Save.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">
                    <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
  •  10-12-2008, 5:01 PM 44824 in reply to 44815

    Re: Reviewing the CuteEditor Database example

    Ken, thanks very much for the sample code.
     
    Is it possible that instead of using the <asp:Button ID="Save" button (placed inside the Repeater) to save the data that the save button from the toolbar could be used to save that data?
  •  10-12-2008, 11:09 PM 44829 in reply to 44824

    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
  •  10-13-2008, 10:18 AM 44835 in reply to 44829

    Re: Reviewing the CuteEditor Database example

    Perfect.....thanks Ken!
View as RSS news feed in XML