Re: Problem with dropdownlist

  •  10-29-2008, 4:01 AM

    Re: Problem with dropdownlist

    Hi jfeeney,
     
    try this way:

    <%@ 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">
        private int index
        {
            get
            {
                object selIndex = this.ViewState["SelIndex"];
                return selIndex == null ? 0 : (int)selIndex;
            }
            set
            {
                this.ViewState["SelIndex"] = value;
            }
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

            Editor1.Text = DropDownList1.SelectedItem.Value;
            Label1.Text = "Working on...." + DropDownList1.SelectedItem.Text;
            DropDownList MyDropDownList = (DropDownList)sender;
            index = MyDropDownList.SelectedIndex;

        }

        protected void Editor1_PostBackCommand(object sender, CommandEventArgs e)
        {

            this.SqlDataSource1.UpdateParameters["PageName"].DefaultValue = DropDownList1.SelectedItem.Text;
            this.SqlDataSource1.UpdateParameters["HTML"].DefaultValue = Editor1.Text;
            this.SqlDataSource1.Update();
            DropDownList1.SelectedIndex = index;
            this.Label1.Text = "saved to...." + DropDownList1.SelectedItem.Text;

        }


        protected void bb1_Click(object sender, EventArgs e)
        {
            this.SqlDataSource1.UpdateParameters["PageName"].DefaultValue = DropDownList1.SelectedItem.Text;

            this.SqlDataSource1.UpdateParameters["HTML"].DefaultValue = Editor1.Text;

            this.SqlDataSource1.Update();
        }
    </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:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
                    DataTextField="PageName" DataValueField="HTML" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Server=(local);uid=sa;pwd=sa;database=test"
                    SelectCommand="SELECT [PageName], [HTML] FROM [T_Pages]" DeleteCommand="DELETE FROM [T_Pages] WHERE [PageName] = @PageName"
                    InsertCommand="INSERT INTO [T_Pages] ([PageName], [HTML]) VALUES (@PageName, @HTML)"
                    UpdateCommand="UPDATE [T_Pages] SET [HTML] = @HTML WHERE [PageName] = @PageName">
                    <DeleteParameters>
                        <asp:Parameter Name="PageName" Type="String" />
                    </DeleteParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="HTML" Type="String" />
                        <asp:Parameter Name="PageName" Type="String" />
                    </UpdateParameters>
                    <InsertParameters>
                        <asp:Parameter Name="PageName" Type="String" />
                        <asp:Parameter Name="HTML" Type="String" />
                    </InsertParameters>
                </asp:SqlDataSource>
                <ce:editor id="Editor1" runat="server" onpostbackcommand="Editor1_PostBackCommand">

    </ce:editor>
            </div>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
               </form>
      
    </body>
    </html>

     
     
    Regards,
     
     
    Ken
View Complete Thread