dropdown SelectedValue

Last post 02-28-2007, 3:44 PM by Adam. 6 replies.
Sort Posts: Previous Next
  •  07-24-2006, 7:38 AM 21182

    dropdown SelectedValue

    Hi,
    I am populating a dropdown in the Editor toolbar using the red code below:
     
    The dropdownlist is populating ok, but I want to be able to display the SelectedValue based on a value obtained from the database. So instead of always displaying the caption "Template" I want to display the name of the template that is brought out of the database - based on its ID.
    As a test, I have tried  ddlTemplates.SelectedItem.Value = 311 (311 is a TemplateID in the database)
    This has the effect of appending the value of 311 to the caption  - resulting in:
    <option value="311" selected="True">Template</option> the value of 311 has been appended to this item. Previously the value was "".
     
    I actually want black_template selected because it has the value of 311 taken from the database.
    <option value="311"> black_template</option>
     
    There does not seem to be the option to get the SelectedValue of a RichDropDownList
     
    Do you have any suggestions?
    Thank you.
     
     
     
    Dim container As System.Web.UI.Control
        container = Editor1.ToolControls("custom").Control
        Dim ddlTemplates As CuteEditor.RichDropDownList
        ddlTemplates = New CuteEditor.RichDropDownList(Editor1)
     
        'must set this css name
        ddlTemplates.CssClass = "~/styles/AcmsMain.css"
        'add the first item (caption)
        ddlTemplates.Items.Add("[[Template]]", "")
     
        'hide the first item (caption) in the float-panel
        ddlTemplates.RichHideFirstItem = True
       
        container.Controls.Add(ddlTemplates)
      
        Dim objRdr As SqlClient.SqlDataReader = Nothing
        objRdr = SiteDB.SiteGetTemplatesByPage(PageID, NewPage)
        If Not Page.IsPostBack Then
          Try
            While objRdr.Read
              ddlTemplates.Items.Add(objRdr("Name"), objRdr("TemplateID"))
              
            End While
          Finally
            objRdr.Close()
          End Try
        End If
     
     
  •  07-24-2006, 2:04 PM 21198 in reply to 21182

    Re: dropdown SelectedValue

    the4bs,
     
    Your code looks ok to me.
     
    >>but I want to be able to display the SelectedValue based on a value obtained from the database
     
    In the above code, you are using CuteEditor.RichDropDownList.
     
    If you want to render some code like <option value="311"> black_template</option>, please use ASP.net DropDownList instead of CuteEditor.RichDropDownList.
     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  07-25-2006, 5:25 AM 21221 in reply to 21198

    Re: dropdown SelectedValue

    Thank you.
     
    Your suggestion worked. I don't know why I assumed I needed to use a RichDropDownList.
     
    Anyway, this is the code that I am now using, which works:
     
      Dim container As System.Web.UI.Control
        container = Editor1.ToolControls("custom").Control
        Dim ddlTemplates As DropDownList
        ddlTemplates = New DropDownList
        ddlTemplates.CssClass = "~/styles/AcmsMain.css"
        ddlTemplates.ToolTip = "Select Template"
        container.Controls.Add(ddlTemplates)
        Dim objRdr As SqlClient.SqlDataReader = Nothing
        objRdr = SiteDB.SiteGetTemplatesByPage(PageID, NewPage)
        If Not Page.IsPostBack Then
          Try
            ddlTemplates.DataTextField = "Name"
            ddlTemplates.DataValueField = "TemplateID"
            ddlTemplates.DataSource = objRdr
            ddlTemplates.DataBind()
            'ddlTemplates.Items.Insert(0, New ListItem("Template", ""))
            ddlTemplates.SelectedValue = ViewState("TemplateID")
          Finally
            objRdr.Close()
          End Try
        End If
  •  02-28-2007, 2:07 PM 27035 in reply to 21221

    Re: dropdown SelectedValue

    I am not sure, why this example is not working for me. My drop down is empty when I use the following code.
     

    If Not objCuteEditor.ToolControls("Number") Is Nothing Then

    Dim container As System.Web.UI.Control

    container = objCuteEditor.ToolControls("Number").Control

    Dim ddlTemplates As DropDownList = New DropDownList

    'ddlTemplates.CssClass = "~/styles/AcmsMain.css"

    'ddlTemplates.ToolTip = "Select Template"

    'ddlTemplates.Items.Insert(0, New ListItem("Template", ""))

    ddlTemplates.Items.Add(New ListItem("1", ""))

    ddlTemplates.Items.Add(New ListItem("2", ""))

    ddlTemplates.Items.Add(New ListItem("3", ""))

    ddlTemplates.Items.Add(New ListItem("4", ""))

    ddlTemplates.Items.Add(New ListItem("5", ""))

    ddlTemplates.Items.Add(New ListItem("6", ""))

    ddlTemplates.Items.Add(New ListItem("7", ""))

    ddlTemplates.Items.Add(New ListItem("8", ""))

    container.Controls.Add(ddlTemplates)
     
    End if
     
    Any help will be much appreciated.
     
    Sam
     
  •  02-28-2007, 2:51 PM 27037 in reply to 27035

    Re: dropdown SelectedValue

    Sam1,
     
    In the  AutoConfigure/Full.config file, do you have an entry like this?
     
    <item type="holder" name="Number" />
     
    if not, can you change "Number" in your code to "insertcustombutonhere"?
    Hope it helps.
     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  02-28-2007, 3:27 PM 27039 in reply to 27037

    Re: dropdown SelectedValue

    Thanks much Adams. That did the trick. One more question. Can I use postback event on the Holder Item (dropdown)? If yes then how?
  •  02-28-2007, 3:44 PM 27040 in reply to 27039

    Re: dropdown SelectedValue

    Sam1,
     
    In this case, you'd better create a regular dropdown control(server control) and add this control to the CuteEditor.
     
     
    create/register a custom button (Server Control) to Cute Editor

    How to create/register a custom button (Server Control) so that it can be used in the template?( C# | VB )

    This example demonstrates how easy it can be to add Server Controls to the CuteEditor and register it into Cute Editor toolbar.


    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

View as RSS news feed in XML