[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

CheckBoxList with Multiple selection set Declaratively

Simon

9/12/2007 10:00:00 PM

Hi,

I'd like to extend the CheckBoxList control so that I can set multiple
selection declaratively. Right now, I'm thinking of simply giving it a
string containing all the selected values, each values separated by a
comma. So, baiscally I have this :

public class TSGControlCheckBoxList :
System.Web.UI.WebControls.CheckBoxList
{
public string SelectedItems
{
set { }
get { }
}
}

Problem is, I'm a complete newbie when it comes to making my own Web
Controls and I have a few questions:

- In the set method for SelectedItems, where should I store my string?
In the viewstate?

- During which phase of the lifecycle should I set the ListItem as
checked by the values in SelectedItems?

- What should the get look like? Would it work to simply go trough all
the ListItem and build my string like that or would an error occur
because they might not yet be built correctly?

So, if you can offer any insight or an example, your help would be
appreciated.

Simon Picard

14 Answers

Teemu Keiski

9/13/2007 4:08:00 PM

0

Hi,

if you think design of CheckBoxList's SelectedItem etc member, you'll note
it's thought to be used basically almost "at any time".
Basically point is that when accessing SelectedItem, it is assumed you have
items and otherwise an exception is thrown. I think it's quite safe to use
this approach with this property. Only exception indeed is that you needf to
delay setting the selections, it could be done in CreateChildControls or
OnInit.

here's an example:

namespace Samples
{
public class MyCheckBoxList : CheckBoxList
{
private string _setItems = null;
public string SelectedItems
{
get
{
//Might be overkill to instantiate Sb every time if you
don't have many items

System.Text.StringBuilder sb = new
System.Text.StringBuilder();
foreach (ListItem item in this.Items)
{
if (item.Selected)
{
sb.Append(item.Value);
sb.Append(",");
}
}

return sb.ToString().TrimEnd(',');
}
set
{
if (value == null) throw new ArgumentNullException("value");
_setItems = value;

}
}

protected override void CreateChildControls()
{
base.CreateChildControls();
if (_setItems != null)
{
foreach (string stringVal in _setItems.Split(','))
{
ListItem item = this.Items.FindByValue(stringVal);
if (item != null)
{
item.Selected = true;
}
}
_setItems = null;
}
}

}
}

and usage:

<%@ Register Namespace="Samples" TagPrefix="cc" %>
....
<cc:MyCheckBoxList ID="CheckBoxList1" runat="server" SelectedItems="2,4">
<Items>
<asp:ListItem Text="Text 1" Value="1" />
<asp:ListItem Text="Text 2" Value="2" />
<asp:ListItem Text="Text 3" Value="3" />
<asp:ListItem Text="Text 4" Value="4" />
<asp:ListItem Text="Text 5" Value="5" />
</Items>
</cc:MyCheckBoxList>


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice....
http://teemu...



"Simon" <drop@step.polymtl.ca> wrote in message
news:1189634421.602454.109180@22g2000hsm.googlegroups.com...
> Hi,
>
> I'd like to extend the CheckBoxList control so that I can set multiple
> selection declaratively. Right now, I'm thinking of simply giving it a
> string containing all the selected values, each values separated by a
> comma. So, baiscally I have this :
>
> public class TSGControlCheckBoxList :
> System.Web.UI.WebControls.CheckBoxList
> {
> public string SelectedItems
> {
> set { }
> get { }
> }
> }
>
> Problem is, I'm a complete newbie when it comes to making my own Web
> Controls and I have a few questions:
>
> - In the set method for SelectedItems, where should I store my string?
> In the viewstate?
>
> - During which phase of the lifecycle should I set the ListItem as
> checked by the values in SelectedItems?
>
> - What should the get look like? Would it work to simply go trough all
> the ListItem and build my string like that or would an error occur
> because they might not yet be built correctly?
>
> So, if you can offer any insight or an example, your help would be
> appreciated.
>
> Simon Picard
>


Simon

9/13/2007 4:20:00 PM

0

Thanks a lot for the example Teemu. I'll try that right away.

Dano

1/4/2010 6:31:00 PM

0

You wanna take this discussion over to the wrestling groups where this
belongs you fuckwit?


Robert Cohen

7/2/2010 1:43:00 PM

0

This posting/blog provides insight into reality of which many anti
zionist postings are rantingly oblivious

http://tmideast.com/2009/04/14/hrgs-prominent-figures-to-battle-durban...

ThomMadura

7/3/2010 11:49:00 PM

0

On 7/3/2010 11:17 AM, no brainer wrote:
>
> Zionist "Jewish" Student Caught Painting Swastikas
> http://www.youtube.com/watch?v=H...
>
> Understand, American refuses to demand this demon
> witch rot in a prison cell, or be formally
> executed. Why? There are literally thousands
> of these crimes every year by the Satanic in
> America, and UNDERSTAND, they claim it is Satan
> that protects them from hate crimes prosecution.
>
> Is God's Will not Just?


Since NO god is proven to exist - no one knows
ANd that means YOU do not know either

Anti-DabianchenVirus

10/5/2010 2:13:00 AM

0

Proof that abianchen/Meichi/report2009 is not "a guy from Taiwan",
like she claims, but an ugly Philippino dyke.

On Jul 13, 12:40 pm, "abianc...@my-deja.com" <abianc...@my-deja.com>
wrote:
> Hey Psycho Xangdi (aka Chairman Mao Says), not sure you want to prove
> abianchen is your Chinese daddy or Meichi is your Filipino mom or
> report2009 is your Chinese grandpa? I am sure abianchen has no problem
> being your Chinese dad since he is your mom's best client. Who knows,
> maybe abianchen is your bio daddy, want to test DNA?

Unable to refute the overwhelming evidence proving that shit face ??
Meichi/Dabianchen/report2009 is an ugly Philippino lesbian
pathological liar, she reverts to her moron mode of childish taunts
against Xangdi's parents, going as far as to present herself as
"Xangdi's father"! This sort of writing can only come from a demented
person with no self-respect and certainly no morals.

Proof that abianchen/Meichi/report2009 is not "a guy from Taiwan",
but
an ugly Philippino dyke:
http://groups.google.com/group/soc.culture.china/msg/31e3f3......
http://groups.google.com/group/soc.culture.china/msg/fc81fe......

Proof that abianchen/Meichi/report2009 can't read/write Chinese other
than cutting-and-pasting from the internet:
http://groups.google.com/group/soc.culture.china/msg/757601......
http://groups.google.com/group/soc.culture.china/msg/282011......
http://groups.google.com/group/soc.culture.china/msg/83029b......
http://groups.google.com/group/soc.culture.china/msg/dd8518......

Proof that abianchen/Meichi/report2009 is a pathological liar:
http://groups.google.com/group/soc.culture.china/msg/ee41fc......
http://groups.google.com/group/soc.culture.china/msg/995a71......
http://groups.google.com/group/soc.culture.china/msg/fdeab5......
http://groups.google.com/group/soc.culture.china/msg/4bdc74......
mode=source
http://groups.google.com/group/soc.culture.china/msg/90a8fd......
http://groups.google.com/group/soc.culture.china/msg/240eb7......

Proof that abianchen/Meichi/report2009 makes persitent childish and
girlish claims:
http://groups.google.com/group/soc.culture.china/msg/7d3d15......

Proof that abianchen/Meichi/report2009 is a loser:
http://groups.google.com/group/soc.culture.china/msg/8af8fd......

Proof that abianchen/Meichi/report2009 is childish and repetitive:
http://groups.google.com/group/soc.culture.china/msg/5646b3......

Anti-DabianchenVirus

1/31/2011 6:54:00 PM

0

Proof that abianchen/Meichi/report2009 is not "a guy from Taiwan",
like she claims, but an ugly Philippino dyke.

On Jul 13, 12:40 pm, "abianc...@my-deja.com" <abianc...@my-deja.com>
wrote:
> Hey Psycho Xangdi (aka Chairman Mao Says), not sure you want to prove
> abianchen is your Chinese daddy or Meichi is your Filipino mom or
> report2009 is your Chinese grandpa? I am sure abianchen has no problem
> being your Chinese dad since he is your mom's best client. Who knows,
> maybe abianchen is your bio daddy, want to test DNA?

Unable to refute the overwhelming evidence proving that shit face ??
Meichi/Dabianchen/report2009 is an ugly Philippino lesbian
pathological liar, she reverts to her moron mode of childish taunts
against Xangdi's parents, going as far as to present herself as
"Xangdi's father"! This sort of writing can only come from a demented
person with no self-respect and certainly no morals.

Proof that abianchen/Meichi/report2009 is not "a guy from Taiwan",
but
an ugly Philippino dyke:
http://groups.google.com/group/soc.culture.china/msg/31e3f3......
http://groups.google.com/group/soc.culture.china/msg/fc81fe......

Proof that abianchen/Meichi/report2009 can't read/write Chinese other
than cutting-and-pasting from the internet:
http://groups.google.com/group/soc.culture.china/msg/757601......
http://groups.google.com/group/soc.culture.china/msg/282011......
http://groups.google.com/group/soc.culture.china/msg/83029b......
http://groups.google.com/group/soc.culture.china/msg/dd8518......

Proof that abianchen/Meichi/report2009 is a pathological liar:
http://groups.google.com/group/soc.culture.china/msg/ee41fc......
http://groups.google.com/group/soc.culture.china/msg/995a71......
http://groups.google.com/group/soc.culture.china/msg/fdeab5......
http://groups.google.com/group/soc.culture.china/msg/4bdc74......
mode=source
http://groups.google.com/group/soc.culture.china/msg/90a8fd......
http://groups.google.com/group/soc.culture.china/msg/240eb7......

Proof that abianchen/Meichi/report2009 makes persitent childish and
girlish claims:
http://groups.google.com/group/soc.culture.china/msg/7d3d15......

Proof that abianchen/Meichi/report2009 is a loser:
http://groups.google.com/group/soc.culture.china/msg/8af8fd......

Proof that abianchen/Meichi/report2009 is childish and repetitive:
http://groups.google.com/group/soc.culture.china/msg/5646b3......

dsharavi

1/31/2011 6:59:00 PM

0

On Jan 31, 10:35 am, Yeah Way Man <amyhaymhnayhnamyh...@hotmail.com>
wrote:
> "RAND PAUL DEMANDS NO MORE AID TO ISRAEL"http://www.truthtellers.org/alerts/RanPaulDemandNoMoreAidI...
> He has made no such demands for Justice.
> Ungodly Nazi Israeli STEAL Innocent Peoples
> Homes routinely with America's Taxes. UNGODLY!

Does Ran Paul alienate his supporters by wanting to get rid of the
Disability Act and Civil Rights? After all; some soldiers from Iraq
and Afghanistan return home with missing limbs. Some of his possible
elderly supporters are disable or will shortly needs assistance. Other
potential votes have hearing and sight issues.

The answer explains a lot about Rand Paul's opposition to the
Americans with Disabilities Act and his implication that he likewise
opposes the Civil Rights Act.

He couldn't even answer the question straight on Maddow either.

Deborah

Jim Higgins

6/19/2011 9:58:00 PM

0

On 6/18/11 4:27 PM, True American Patriot wrote:
>zip

Terminally Boring-Guilty as charged

--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---

billzz

6/20/2011 3:00:00 AM

0

On Jun 19, 2:57 pm, Jim Higgins <gordian...@hotmail.com> wrote:
> On 6/18/11 4:27 PM, True American Patriot wrote:
>
> >zip
>
> Terminally Boring-Guilty as charged
>
> --- Posted via news://freenews.netfront.net/ - Complaints to n...@netfront.net ---

Whenever I see something that looks like...

/ / word word word \
I know to leave.