473,569 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:dropdownlis t 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
<DefaultPropert y("SelectedValu e"), ToolboxData("<{ 0}:TestList
runat=server></{0}:TestList>") > Public Class TestList
Inherits System.Web.UI.W ebControls.Drop DownList

Dim _selected As String

<Bindable(True) , Category("Data" ), DefaultValue("A A")> 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.H tmlTextWriter)
Dim strTxt as String

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

output.Write(st rTxt)

End Sub

End Class
Nov 19 '05 #1
1 2595
Render outputs the control's html. rendering "<asp:DropDownL ist 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*********@eN etPortals.com> wrote in message
news:pm******** ********@newsre ad3.news.atl.ea rthlink.net...
Hi -

I'm creating a web control library (using VB.NET), and I'm trying to add a
modified asp:dropdownlis t 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
<DefaultPropert y("SelectedValu e"), ToolboxData("<{ 0}:TestList
runat=server></{0}:TestList>") > Public Class TestList
Inherits System.Web.UI.W ebControls.Drop DownList

Dim _selected As String

<Bindable(True) , Category("Data" ), DefaultValue("A A")> 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.H tmlTextWriter)
Dim strTxt as String

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

output.Write(st rTxt)

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
9681
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 box value and the text are the same (The ListItem.Text), How do I get the ListItem.Text to render as the text and the ListItem.Value to be the html...
1
1306
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 simple syntax issue? I've attempted my due diligence with the usual books and references...but I'm new to ASP.NET. Question follows: The Code...
1
2151
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 = xmlDoc.SelectNodes("/engines/engine")
1
3552
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 dropdownlist but still show the entire text of the listitem option. Observations: 1. Setting the dropdownlist to a fixed width chops off the option...
3
2625
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 dropdownlist, because a database query in codebehind has to be done, when a new listItem is selected. So, I need to use a servercontrol dropdownlist. ...
0
1627
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 again 'cause its value are saved (i assume viewstate). Well. I have a class that inherits from WebControl and INamingContainer. This class Load an...
2
1803
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 unknown types. eg... <mytag:mydropdownlist id="lstInherited" runat="server" appenddatabounditems="true" > <asp:listitem id="" value="select an...
3
10740
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: dropdownlist control doesn't need viewstate for keeping the value when the ListItems are put declaratively. Why not when the ListItems are put...
1
1635
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 Protected Overrides Sub RenderContents(ByVal writer As System.Web.UI.HtmlTextWriter) 'I add several items to the Items property here using...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.