Sometimes you're navigating in the MSDN Library and you spot an error in the documentation. You decide to send your feedback and you might wonder if someone reads your comments. Yes, we do! And we take them very seriously!
From small typos to missing code samples to more serious errors, we analyze the comments and make the changes as possible.
One example of a topic that was changed based on the user feedback was the reference for the GridView.RowEditing event. Some of the comments were asking for examples of how to use this event when you are setting the data source programatically and not using the DataSourceID property. So, in the new release of the documentation we added a new sample to the property with the comments in mind.
You can compare the new version with the previous one!
But, for us, it's also important that you give us positive feedbacks when you find useful topics. This helps us track when we're doing it right as well and use that as a model to be followed!
Yesterday a new release of the ASP.NET Dynamic Data Preview was posted on Code Gallery.
Dynamic Data uses a data model to interact with the underlying database. From the data model, Dynamic Data reads the metadata information to perform some built-in operations, such as, type validations or a required field validation. But you can extend the data model and add some extra metadata to a table or a particular field by using attributes.
These attributes are in two namespaces: System.ComponentModel and System.ComponentModel.DataAnnotations.
Here is the list of attributes you can use:
Adds additional information about a data field, that is commonly treated as a plain string. Options include:
To apply an attribute to a table or a particular field, you cannot change the class generated by the O/R Designer or you will end up losing the changes if you update the data model.
So the way you do this with Dynamic Data, is that you first create a partial class with name of your table. If the metadata refers to the table, you can apply the attribute in this partial class. For example:
[DisplayColumn("FirstName")] public partial class Employee { }
But, when you want to add metadata to a particular field, you also need to create a special metadata class where you're going to apply the attribute to a particular field. And then, you're going to connect the partial entity class with this metadata class with the MetadataTypeAttribute, like in the following example:
[MetadataType(typeof(ProductMetaData))] public partial class Product { } public class ProductMetaData { [DisplayFormat(DataFormatString = "{0:C}")] public object UnitPrice { get; set; } }
I'll keep posting on Dynamic Data!
When you're working with data-bound controls and you want control over the generated markup, you end up using templated data-bound controls such as the FormView or ListView controls, or the TemplateField of a GridView control.
But even when you're using these templated controls, sometimes you don't have real control over the generated markup. For example, if you have an Image control inside the ItemTemplate like the following code:
<asp:Image runat="server" ID="ThumbnailImage" ImageUrl='<%# Eval("FileName", "images/{0}")>%'> </asp:Image>
The generated markup will contain an additional style element that you haven't defined in your Web server control, like the following:
<img id="PhotoListView_ctrl0_ThumbnailImage" src="images/image1.jpg" style="border-width:0px;" />
This happens because a Web control is not necessarily completely customizable. If you really need complete control over your final generated markup, i.e, you just want to show what you have defined, you can use HTML server controls. An HTML server control is an HTML element with a runat="server" attribute. In the last example, you could replace the Image control, with the <img> HTML element like the following:
<img runat="server" id="ThumbnailImage" src='<%# Eval("FileName", "images/{0}")>%' />
The end result is the same, however behind-the-scenes the generated markup does not contain anything extra, only what you have defined, as the following:
<img id="PhotoListView_ctrl0_ThumbnailImage" src="images/image1.jpg" />