public knowledge blog_load(sender Virendra)

                                                                                                                          Nothing shocks me, I am a Software Engineer.

ASP.NET 4.0 : FormView Control Enhancements

Posted by Virendra Dugar on May 22, 2009

The FormView control is data-bound control that is nothing but a templated version of DetailsView control is designed to give you full control over the rendered markup. Bydefault, FormView control gets rendered as HTML table.  Consider this example :

<asp:FormView ID="FormView1" runat="server">
  
<ItemTemplate>
    Content goes here!
   </ItemTemplate>
</asp:FormView>

This gets rendered like :

<table cellspacing="0" border="0" id="FormView1" style="border-collapse:collapse;">
  <tr>
    <td colspan="2">
        Content goes here!
   </td>
  </tr>
</table>

ASP.NET 4.0 comes with new property RenderTable which lets you specify whether the FormView control renders using a table.  This is how you specify it..

<asp:FormView ID="FormView1"runat="server" RenderTable="false">

 
If this property is used with previous example then the output will be without table, tr and td tag:

Content goes here!

This enhancement can make it easier to style the content of the control with CSS, because no unexpected tags are rendered by the control..

Enjoy…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: