Andy Smith's Blog

Page.RegisterStartupScript('Andy', 'MetaBuilders_WebControls_GainKnowledge();');

thinking about CheckBoxList

I was thinking about the CheckBoxList control today, and it hit me that while you can set the DataTextField and DataValueField properties, a really useful one would be a DataSelectedField property, which pointed to a boolean field in the row which indicated the Selected property of the ListItem, which would translate to the Checked property of the checkbox.

To implement that, I'll probably have to subclass CheckBoxList and reimplement DataBind. At first I thought I could just override it, and run thru the datasource again, but then I thought about the scenario where people bind to DataReaders, which can't be read thru twice. So I guess it's up to me to reimplement the whole function.

What would have been useful is if the DataBind method seperated out the itteration of the datasource, with the application of each item's information. Something along the lines of a protected virtual method that got passed one item from the enumeration and the ListItem to be affected.

I realize it wouldn't make much sense for the basic implementation of the control, but it's really really usefull for somebody extending the control.

I'm thinking I might even make an event for this, so that others could even more easily extend it to allow for setting colors or whatever based on the ListItem and currently enumerated data object/row.

Comments

Corey Alguire said:

Andy, this is a fantastic idea. Did you ever get around to coding it? I someone looking over a sample application I built for him today ask me if it was possible to do this, so I am looking for some code that already has the functionality before I spend the time to do it myself. If you have already coded this, I would love to see it. ishmaelatsea@yahoo.com
# January 15, 2004 2:19 PM

Jeremy said:

I spent three hours today searching MSDN for samples on how to bind the selected property. I thought at least that the checkboxlist would have an itemdatabound event, like the datagrid.

Thanks for the post - now I know I'm not the only one who is dreaming of such a feature :D

I am going to use a datagrid and just make it look like a checkboxlist to the user.
# July 21, 2004 6:03 PM

Peter Bucher said:

Hi there

I have wrote a CustomControl that implements your idea. While searching for ideas i found this blog post.

Maybe your intrested in my current solution, especialy how to handle with IDataReader DataSources.

my blog post is written in german, but that would not be a problem, hope so :-)

[Blog Post]

- www.aspnetzone.de/.../eintraege-der-checkboxlist-beim-databinding-vorselektieren.aspx

[Test Project Download]

- www.aspnetzone.de/.../download.aspx

HTH

# September 3, 2007 6:41 PM

Jed said:

Could you help me. He was one of those men who think that the world can be saved by writing a pamphlet. Help me! Help to find sites on the: Share trading class chennai. I found only this - <a href="leadership.nlada.org/.../ShareTrading">broker discount online share stock trading</a>. Share trading, he hits tax markets, shares, during the growth ways. Share trading, after 1995-96 the functionality affirmed and management equity and trading differed that capability method for most of the accounts. Thanks :rolleyes:. Jed from Benin.

# March 25, 2010 12:53 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)