473,323 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

DropDownList ListItems in a VB.NET Web Control Library

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
Nov 19 '05 #1
1 2584
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)

"Jeff" <je*********@eNetPortals.com> wrote in message
news:pm****************@newsread3.news.atl.earthli nk.net...
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DesignerX | last post by:
I am being sent an ArrayList of ListItems. I can bind to a dropdownlist control using: oDropDownList.DataSource = oArrayList This works but when the dropdownlist is rendered both the select...
1
by: | last post by:
This is a crosspost from a less-frequented (but more focused) asp.net group; I didn't receive an answer that worked. I'd like to get this form functional. Could someone help on what's probably a...
1
by: Joe Gass | last post by:
I'd like to bind some xml to a dropdownlist <engines> <engine name="test1" id="1" /> <engine name="test2" id="2" /> </engines> If I do: ddlEngines.DataSource =...
1
by: HoustonFreeways | last post by:
I am populating a dropdownlist via a databind to a database. However, the text to be displayed can be very long, making the dropdownlist very wide. I need some way to reduce the width of the...
3
by: RFS666 | last post by:
Hello together, I tried to find out about populating an asp.net server control (a dropdownlist) from the clientside jscript, but I didn't find a solution up to now. I cannot use a html...
0
by: Jose Fernandez | last post by:
Hello First of all, excuse my english We all know that in a normal page with codebehind we add a dropdownlist control and we bind() it in the (!ISPOSTBACK), so, we don't need to go to database...
2
by: Arthur Dent | last post by:
Hi all, I have a control which i wrote which inherits the asp:dropdownlist control. Works great, all happy. If when using it i try to declaratively add some items, it complains that they are...
3
by: Bart | last post by:
Hi, This code sends back the selectedvalue of a dropdownlist to itself (postabck). But the value (dd in the code) is empty. I must say: it works with EnableViewState="true". My question is:...
1
by: Nathan Sokalski | last post by:
I am creating a control in which I inherit from the DropDownList. The only method that I override is RenderContents. Here is my basic code: Public Class StatesDropDownList : Inherits DropDownList...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.