DropDownList ListItems in a VB.NET Web Control Library

J

Jeff

Hi -

I'm creating a web control library (using VB.NET), and I'm trying to add a
modified asp:dropdownlist control to it.

How do I add asp:ListItems to the dropdownlist (within the web control
library control)?

My code follows below (and it doesn't work). When I add the control to an
aspx page, I simply get a string of the concatenated values ("First
ValueSecond ValueThird Value") displayed; no dropdownlist.

Thanks for your help.

- Jeff


<DefaultProperty("SelectedValue"), ToolboxData("<{0}:TestList
runat=server></{0}:TestList>")> Public Class TestList
Inherits System.Web.UI.WebControls.DropDownList

Dim _selected As String

<Bindable(True), Category("Data"), DefaultValue("AA")> Overrides
Property [SelectedValue]() As String
Get
Return _selected
End Get

Set(ByVal Value As String)
_selected = Value
End Set
End Property

Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
Dim strTxt as String

strTxt = ""
strTxt &= "<asp:DropDownList id='ddlList' runat='server'>"
strTxt &= "<asp:ListItem Value='AA'"
If [SelectedValue] = "AA" Then strTxt &= " Selected='True'"
strTxt &= ">First Value</asp:ListItem>"
strTxt &= "<asp:ListItem Value='BB'"
If [SelectedValue] = "BB" Then strTxt &= " Selected='True'"
strTxt &= ">Second Value</asp:ListItem>"
strTxt &= "<asp:ListItem Value='CC'"
If [SelectedValue] = "CC" Then strTxt &= " Selected='True'"
strTxt &= ">Third Value</asp:ListItem>"
strTxt &= "</asp:DropDownList>"

output.Write(strTxt)

End Sub

End Class
 
B

Bruce Barker

Render outputs the control's html. rendering "<asp:DropDownList id>" is
meanless to a browser. read docs on composite controls to better understand
what you are trying to do.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top