Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.

Sunday, February 10, 2008

Creating a ListItemCollection Template User Control

Creating a ListItemCollection Template User Control. Here are the 3 files necessary. A link to the reference link is below.

First: The user control code-behind:

[DefaultEvent("SelectedIndexChanged"),
Designer("System.Web.UI.Design.WebControls.ListControlDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
ParseChildren(true, "Items"), ControlValueProperty("SelectedValue"),
DataBindingHandler("System.Web.UI.Design.WebControls.ListControlDataBindingHandler, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public partial class ComboBoxControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

}
private ListItemCollection m_Items;

[DefaultValue((string)null), MergableProperty(false),
PersistenceMode(PersistenceMode.InnerDefaultProperty),
Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor,System.Design, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
typeof(UITypeEditor))]
public virtual ListItemCollection Items
{
get
{
if (this.m_Items == null)
{
this.m_Items = new ListItemCollection();
}
return this.m_Items;
}
}
protected override void CreateChildControls()
{
if (this.m_Items == null)
{
this.m_Items = new ListItemCollection();
}

if (m_Items.Count>0) {
foreach (ListItem item in m_Items)
{
_ComboBoxControl.Items.Add(item);
}
}
}
public override void DataBind()
{
CreateChildControls();
ChildControlsCreated = true;
_ComboBoxControl.DataBind();
base.DataBind();
}
}
Next, the User control

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ComboBoxControl.ascx.cs" Inherits="ComboBoxControl" %>
<asp:DropDownList ID="_ComboBoxControl" runat="server">
</asp:DropDownList>
And finally the aspx:

<uc1:ComboBoxControl ID="ComboBoxControl1" runat="server">
<Items>
<asp:ListItem Value="Value1" Text="Text1" />
<asp:ListItem Value="Value2" Text="Text2" />
<asp:ListItem Value="Value3" Text="Text3" />
<asp:ListItem Value="Value4" Text="Text4" />
</Items>
</uc1:ComboBoxControl>


Credit to: http://developers.de/blogs/damir_dobric/archive/2007/03/30/Implementing-Custom-UserControl-with-ListItem-collection.aspx

15 comments:

Unknown said...

Thanks a lot, this is just what I was looking for!

Anonymous said...

You did a good job in researching vimax and writing your content. vimax pills This is good information that will help others. penis enlargement pills
Great job~ [url=http://pills.buypenisenlargement.com]vimax[/url] [url=http://pills.buypenisenlargement.com]vimax pills[/url] [url=http://pills.buypenisenlargement.com]penis enlargement pills[/url]

Unknown said...

Hi!

I'm getting an error for this code. VS 2005.

The error message:
-------------------
Generation of designer file failed: System.Web.UI.WebControls.ListItemCollection must have items of type 'System.Web.UI.WebControls.ListItem'. 'Items' is of type 'System.Web.UI.HtmlControls.HtmlGenericControl'.
------------------------
But, The type of Items property and its private attribute are already System.Web.UI.WebControls.ListItem;

Any tips? Thanks in advance!

Unknown said...

Oh! Sorry. I closed and reopen VS 2005 and it works fine!

Anonymous said...

Pay Day Loan http://www.2applyforcash.com/ BulaacepupBlone instant payday loans online Hakyhychoak [url=http://www.2applyforcash.com]Payday Loans Online[/url] Payday Loans Online Avoid writing in to visit it regardless of his or her own experience online?Teens could make your goals and achieve them because no one else can do this job for you.By reading the review on this fantastic new of specialization, you can generate heavy traffic to your site?

Anonymous said...

http://www.hs.syreen.de/fankurve/fan-tagebuch/test-und-freundschaftsspiele/waiver-translations-stalker-same-day-payday-loans BulaacepupBlone start a business with £1000 Hakyhychoak [url=http://www.worldusabilityday.org/online-payday-loans-instant-approval-implementation-omara-diss-theoretically-scimitar-undersea]making money at home[/url]

Anonymous said...

online payday loans no credit check http://legitpaydayloansonline3.com Fundpopog Payday loans online Stype [url=http://www.legitpaydayloansonline3.com]payday loans online[/url] Cheap Payday Loans Online Our company's online marketing organization amount more afford of loan from the comfort of your home...It is very difficult to get approved within an collected before committing to a given lending institution.

Anonymous said...

buy ativan ativan extended release - ativan withdrawal plan

Anonymous said...

http://libjournal.uncg.edu/index.php/index/user/profile

Anonymous said...

That wasn't the only Elixir Revolution this brought in a lot more scratch than was originally estimated. I know this has been a long winded story. Perhaps I may be too enthralled by my affair. I recommend you try it sometime. They need to buy new. Look, I would recommend that you place your attention to this arrangement. What's in that for me? How will that fit into your plan, if at all?
This just wouldn't be the same without that.
You don't need to take an amateur approach with this. Where should We start? That is just one benefit that find will pay for.
Elixir Revolution

Empowered Boost said...



I could easily sell them a Uneeq Serum. They have an attractive style. It is type of gross.

Let's take advantage of this. I suggest that you do so. That maneuver confuses us occasionally. These are a few workable notions. This article is going to try to respond to quite hard question. No one tracks the precise numbers now. Uneeq Serum becomes more popular as more Uneeq Serum designs are provided to more coalitions. Interesting thought, don't you imagine? Uneeq Serum information can be easily learned through a Uneeq Serum forum. I suppose that these are practical plans. Allow me grab their attention for a minute and also that all depends. How wonderful. I strongly give my support for this primo intimation.

You don't see umpteen of those about anymore. It is clear to me this I can shy away from that as soon as they can.



Uneeq Serum

Unknown said...

Dianabol
legal steroids for sale
steroids that work
legal steroids that work
legal steroid gnc
anabolic supplements gnc
legal anabolic steroids gnc
D-Bal’s powerful formula mimics the effects of Methandrostenolone, otherwise known as Dianabol, the granddaddy of steroids. Dianabol represents one of the most popular and one of the most important anabolic steroids of all time

Unknown said...

phenq canada Wow I can say that this is another great article as expected of this blog.Bookmarked this site.

Weightloss said...

big-job Wow I can say that this is another great article as expected of this blog.Bookmarked this site.

Weightloss said...

mensreviewmonster Wow I can say that this is another great article as expected of this blog.Bookmarked this site.