By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,694 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,694 IT Pros & Developers. It's quick & easy.

Using Custom DropDownList in UserControl

P: n/a
Joe
Hello All:

I have created a class (UpdatedDropDown) that inherits from DropDownList and
I have included the following code in this class:

Public Class UpdatedDropDown
Inherits DropDownList

Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
For c As Integer = 0 To Items.Count - 1
Dim li As ListItem = Items(c)
writer.WriteBeginTag("option")
If li.Selected Then
writer.WriteAttribute("selected", "selected", False)
End If
writer.WriteAttribute("value", li.Value, True)
Dim AttrEnum As System.Collections.IEnumerator =
Items(c).Attributes.Keys.GetEnumerator
Do While AttrEnum.MoveNext
writer.WriteAttribute(CType(AttrEnum.Current, String),
CType(AttrEnum.Current, String))
Loop
writer.Write(">")
System.Web.HttpUtility.HtmlEncode(li.Text, writer)
writer.WriteEndTag("option")
writer.WriteLine()
Next
End Sub
End Class

I am doing this so that I can render the style attribute in the ListItems
contained in the DropDownList.

I now want to use this control in a UserControl called
AugmentedDropDownList. Here is the HTML markup for the UserControl:

<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="AugmentedDropDownList.ascx.vb"
Inherits="WBMI.Claims.AugmentedDropDownList"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<%@ Register TagPrefix="UDD" TagName="UpdatedDropDown"
src="../Classes/UpdatedDropDown.vb"%>
<TABLE class="interior" id="Table1" width="100%">
<TR>
<TD width="150" class="tabledata"><asp:label id="Label1"
runat="server"></asp:label></TD>
<TD class="tabledata"><UDD:UpdatedDropDown id="DropDownList1"
runat="server"></UDD:UpdatedDropDown></TD>
</TR>
</TABLE>

UpdatedDropDownList is contained in a directory called Classes and
AugmentedDropDownList is located in a directory called UserControls. These
two directories are "sibling' directories (they are on the same level within
the file system tree structure).

This is not working, probably because I'm not sure what I'm doing. Can
anyone help me figure out why, when I 'View Design' on the UserControl, I see
that there was an error creating the controls in AugmentedDropDownList?

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
Dec 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Joe
Never mind. Found a workaround.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Joe" wrote:
Hello All:

I have created a class (UpdatedDropDown) that inherits from DropDownList and
I have included the following code in this class:

Public Class UpdatedDropDown
Inherits DropDownList

Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
For c As Integer = 0 To Items.Count - 1
Dim li As ListItem = Items(c)
writer.WriteBeginTag("option")
If li.Selected Then
writer.WriteAttribute("selected", "selected", False)
End If
writer.WriteAttribute("value", li.Value, True)
Dim AttrEnum As System.Collections.IEnumerator =
Items(c).Attributes.Keys.GetEnumerator
Do While AttrEnum.MoveNext
writer.WriteAttribute(CType(AttrEnum.Current, String),
CType(AttrEnum.Current, String))
Loop
writer.Write(">")
System.Web.HttpUtility.HtmlEncode(li.Text, writer)
writer.WriteEndTag("option")
writer.WriteLine()
Next
End Sub
End Class

I am doing this so that I can render the style attribute in the ListItems
contained in the DropDownList.

I now want to use this control in a UserControl called
AugmentedDropDownList. Here is the HTML markup for the UserControl:

<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="AugmentedDropDownList.ascx.vb"
Inherits="WBMI.Claims.AugmentedDropDownList"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<%@ Register TagPrefix="UDD" TagName="UpdatedDropDown"
src="../Classes/UpdatedDropDown.vb"%>
<TABLE class="interior" id="Table1" width="100%">
<TR>
<TD width="150" class="tabledata"><asp:label id="Label1"
runat="server"></asp:label></TD>
<TD class="tabledata"><UDD:UpdatedDropDown id="DropDownList1"
runat="server"></UDD:UpdatedDropDown></TD>
</TR>
</TABLE>

UpdatedDropDownList is contained in a directory called Classes and
AugmentedDropDownList is located in a directory called UserControls. These
two directories are "sibling' directories (they are on the same level within
the file system tree structure).

This is not working, probably because I'm not sure what I'm doing. Can
anyone help me figure out why, when I 'View Design' on the UserControl, I see
that there was an error creating the controls in AugmentedDropDownList?

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation

Dec 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.