Urgent - Getting DropDownList value

Last post 07-26-2006, 5:13 AM by the4bs. 0 replies.
Sort Posts: Previous Next
  •  07-26-2006, 5:13 AM 21254

    Urgent - Getting DropDownList value

    Hi,
     
     
    I have a custom dropdownlist in the Editor toolbar. It was created with code like this:
     
    Protected Sub PopulateTemplateDropDown()
     
        Dim PageID, NewPage As Integer
        PageID = Session(SessTypes.TreeViewID)
        If (Request.QueryString("Edit")) = Nothing Then
          NewPage = 1
        Else
          NewPage = 0
        End If
     
        Dim container As System.Web.UI.Control
        container = Editor1.ToolControls("custom").Control
        Dim ddlTemplates As DropDownList
        ddlTemplates = New DropDownList
        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.SelectedValue = ViewState("TemplateID")

          Finally
            objRdr.Close()
          End Try
        End If
      End Sub
     
    I want to get the selectedItem.Value of that dropdown - because I want to insert it into the database - like I do with the Editor content.
     
    I have tried various ways, including:
     
      Protected Sub Submit()
       ............
      Dim ddlTemplates As DropDownList
     Dim TemplateID AS Integer
        ddlTemplates = Editor1.ToolControls("custom").Control.FindControl("ddlTemplates")
        'ddlTemplates = Editor1.FindControl("ddlTemplates")

         If Not ddlTemplates Is Nothing Then
          TemplateID = ddlTemplates.SelectedItem.Value
        End If
     
        ..............
    End Sub
     
     
    The value I get returned is 0 - which is wrong
     
    How do I get the selectedItem.Value?
     
    Thank you.
     
View as RSS news feed in XML