Creating Custom Label Controls
page 2 of 6
by Brian Mains
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 27423/ 81

Data Bound List Issue

When used in a data binding situation, the label is often used to represent read-only data. When the data bound control is rendered in edit mode, a text box is used to edit the data. However, sometimes a list is used, which performs two bindings (depending on the situation). The first binding is the binding of all the possible values in the list. The second binding is which value was selected in the list. However, in view mode, this means some challenges; for instance, oftentimes the value stored in the database is an encoded value (like O for Open and C for close). This means that the value has to be converted, which may not be a challenge.

Let's use for example a United States state code field.  In the database, it stores PA for Pennsylvania, NY for New York, etc.  In edit mode, a drop down list is used, showing Pennsylvania and New York values spelled out; however, the underlying value is the encoded two-letter form.  In read-only mode, whenever the main data source is bound, it only knows about the two-letter form.

There are multiple solutions to this. The first is to translate the value. The GridView control has a RowDataBound method that can be used to tap into the rows/cells, and change the value stored in the cell (if that is the control that is being used). Another alternative is to include both the code and the name in the underlying data source. But with a little customization, another alternative is possible; that is what we will look at next.


View Entire Article

User Comments

Title: fert   
Name: fo kos
Date: 2012-12-10 8:56:24 AM
Comment:
fo kos kos ley kos
Title: Nice Addition   
Name: Michael Davey
Date: 2007-11-29 8:46:40 AM
Comment:
Neat additions to the label control.. thanks!






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-03-08 7:36:47 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search