Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent asp:FormView from rendering as a table?

Tags:

I have an asp:FormView with an ItemTemplate. I'd like to design the content within the FormView with some div elements:

<asp:FormView ID="MyFormView" runat="server" >     <ItemTemplate>         <div class="block1">             Stuff...         </div>         <div class="block2">             Stuff...         </div>          ...          <div class="blockN">             Stuff...         </div>     </ItemTemplate> </asp:FormView> 

When I run the application the following HTML is created:

<table id="MyFormView" style="border-collapse: collapse;" border="0" cellspacing="0">     <tbody>         <tr>             <td colspan="2">                 <div class="block1">                     Stuff...                 </div>                 <div class="block2">                     Stuff...                 </div>                  ...                  <div class="blockN">                     Stuff...                 </div>             </td>         </tr>     </tbody> </table> 

Actually the table is somewhat disturbing. I don't know what's the purpose to have an ItemTemplate to freestyle the content but then wrap it into a table.

Is it possible to disable or work around this behaviour? (I couldn't find a flag in the FormView properties.)

like image 259
Slauma Avatar asked Mar 09 '10 19:03

Slauma


People also ask

Which of the following is not a valid template for FormView?

You can't add a BoundField or TemplateField to a FormView.

What is FormView control in asp net?

The FormView control is used to display a single record from a data source. It is similar to the DetailsView control, except it displays user-defined templates instead of row fields.

Which of Form view is used to display the data from the data source in read only mode?

The FormView control is in insert mode, which allows the user to add a new record to the data source. The FormView control is in read-only mode, which is the normal display mode.


2 Answers

You can set RenderOuterTable="false" on the FormView

like image 162
Clover Avatar answered Sep 22 '22 04:09

Clover


Use the following code.

RenderOuterTable="false" 

Put it on the FormView. It works in .NET 4.0.

like image 30
Jeditor Avatar answered Sep 22 '22 04:09

Jeditor