ListControl Items, Attributes, and ViewState 02 Nov 2005 00:00 GMT
ASP.NET 1.x provides four Web controls that serve as list controls:
- The DropDownList,
- The CheckBoxList,
- The RadioButtonList, and
- The ListBox
One nuisance shared among all controls is the fact that their items don't render attributes. For example, imagine that you
wanted to display a CheckBoxList with particular CheckBoxes in the list displayed using a certain CSS class; or maybe when
a particular RadioButton in a RadioButtonList control is selected, you want to run some client-side JavaScript. These
are features that would be typically set using the CheckBox or RadioButton Web control's Attributes collection.
Unfortunately, when a list control is rendered it does not render the attributes of the items.
In a previous article of mine, ListControl Items and
Attributes, I discussed one technique for adding attribute support to the ASP.NET 1.x list controls. Specifically, I looked
at extending the CheckBoxList class and overriding the Render() method to squirt out the
ListItem's attributes. This culminated in a
live demo that showed how to create a CheckBoxList that included a 'None' option that, when checked, would use
client-side JavaScript to automatically unselect all other checkboxes in the CheckBoxList.
In the article, however, I pointed out one drawback of my code: the attributes specified for the ListItems were
not saved in ViewState. That means that these attribute values are not persisted across postbacks; they
must be reinjected into the ListControl's ListItems on each postback, as was done in the
live demo from the previous article. This article examines how to augment the code examined from the previous article to
persist the ListItem attributes in ViewState. Read on to learn more!
I strongly encourage you to first read ListControl Items and
Attributes before tackling this article...
Read More >
Source: 4GuysFromRolla An Overview of Visual Basic 2005 01 Nov 2005 23:12 GMTGet on overview of the new features in Visual Basic 2005 including, My Visual Basic, IntelliSense, Edit and Continue, AutoCorrect, Just My Code, Windows Forms enhancements, and more.
Source: MSDN