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

24 comments:

Carbito 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]

Anonymous said...

HELP! I’m currently being held prisoner by the Russian mafia xyzrxyz [url=http://www.buypenisenlargement.com]penis enlargement[/url] xyzrxyz and being forced to post spam comments on blogs and forum! If you don’t approve this they will kill me. xyzrxyz [url=http://www.buypenisenlargement.com]penis enlargement[/url] xyzrxyz They’re coming back now. xyzrxyz [url=http:/pills.buypenisenlargement.com]vimax[/url] xyzrxyz Please send help!

Paulo Fonseca Jr. 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!

Paulo Fonseca Jr. 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

Sara Martin said...

Top Legal Anabolic Steroids

Silly Martin said...

I Have Been wondering about this issue, so thanks for posting.
vigrx plus

Angel Marvel said...

Don’t Buy Phen375 Diet Pills until you read My REVIEW based on Real and Fully Researched Information! Side Effects, Ingredients and User Feedback

Silly Martin said...

If you are looking for some reliable way to shed the excess amount of unwanted fat from your body then the best option is Forskolin Fuel http://www.wheretobuyforskolinfuel.com/
Forskolin Fuel

Dianabol for sale said...

Looking for proven, effective Dianabol for Sale without side effects? Discover premium Dbal-Max Pills currently helping guys build mass safely. http://www.dbalmax-reviews.com/

Vanessa duke said...

Breast Actives
is a 3 step all natural solution for breast enlargement, combining breast pills, cream and a breast exercise and massage program.http://www.breastactivesbuy.com/

best smart drugs said...

" best smart drugs Smart pills' are becoming increasingly popular among career women. But do they really boost your brain power. http://www.noocube-review.com/"

Nootropics said...

" Nootropics or smart drugs, are being used around the world by students, entrepreneurs, small business owners, athletes, poker players and housewives. http://www.noocube-review.com/"

Male Extra said...

Male Extra pills are famous on the market. But you have to know some side effects and results. My prof review will help you. http://www.maleextrareviewguide.com

Gina Schwaer said...

having more sex can make you live longer Male Extra pills are famous on the market. But you have to know some side effects and results. My prof review will help you.

how to make your vagina tighter said...

how to make your vagina tighter Many women also consider v tight gel after having children. During natural childbirth the vaginal muscles expand to form the birth canal for your baby. http://vtightgelreviewer.com

Leidy Ordonez said...

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

Elixir Revolution 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

Uneeq Serum 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