Tech Tutorials Database
GeekArticles Database SQL Server
 

ListControl Items, Attributes, and ViewState

 
Author: aspnet.4guysfromrolla.com
Category: SQL Server
Comments (0)

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 >

Read More...




Sponsored Links




Read Next: Coding-in-SQL issue: A SQLCLR Stored Procedure to Write to a Trace File



 

 

Comments



Post Your Comment:

Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe