Personal Web & Sample Site
Skip Navigation Links
HOME |
About Me |
Articles
| Contact Us
Custom Formatting - DetailsView Template Field Example
Rating: 10 user(s) have rated this article Average rating: 5.0
Posted by: joet, on 8/10/2011, in category "MS SQL"
Views: this article has been read 4502 times
Location: Houston, Tx, United States
Abstract: Other cool examples from Scott Mitchell's data tutorial involves modifying a template field in the DetailsView control. This time instead of modfying a field I deleted those that I was replacing and then added a new TemplateField. Then I added three lables and then binded each label to a different data source, except for the first label that simply says "(In Stock / On Order)". Of course we added the object data source like before and then used the GetProducts" method and then modified the field names and deleted some others.

 

 

Go here for example!

 

The other example presented on this page is another formatting method like before, in the code-behinds page that's called from the "ItemTemplate" that shows a different formatting of "Yes" or "No". This time the method was much simpler:

protected string DisplayDiscontinuedAsYesorNo(bool discontinued) { if (discontinued) return "Yes"; else return "No"; }

Then in the ItemTemplate field we change the markup to:

<asp:TemplateField HeaderText="Discontinued" SortExpression="Discontinued">
<ItemTemplate>
<%# DisplayDiscontinuedAsYESorNO((bool) Eval("Discontinued")) %>
</ItemTemplate>
</asp:TemplateField>

Pretty simple right?

 


How would you rate this article?

User Feedback

Post your comment
Name:
E-mail:
Comment:
Insert Cancel

Copyright © 2013 Jose M. Tamez
Last Updated August 18th 2013