22

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.)

Slauma
  • 175,098
  • 59
  • 401
  • 420
  • Would a ListView be useful here? You have more control over the LayoutTemplate. – Glen Little Mar 09 '10 at 20:16
  • If there are not other way I might consider this. I have only one object to display in a form, not a list. So the most "natural" control seemed to be a FormView at a first glance. Anyway, thanks for the tip! – Slauma Mar 09 '10 at 20:25

3 Answers3

65

You can set RenderOuterTable="false" on the FormView

Doug Domeny
  • 4,410
  • 2
  • 33
  • 49
Clover
  • 751
  • 5
  • 4
11

Use the following code.

RenderOuterTable="false"

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

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
Jeditor
  • 111
  • 1
  • 2
3

use repeater (it is light version and fully customizable)

  <asp:Repeater runat=server ID="r1">
<HeaderTemplate><div></HeaderTemplate>
<ItemTemplate>Zzz</ItemTemplate>
<FooterTemplate></div></FooterTemplate>
</asp:Repeater>  

or

better use control adapters:

garik
  • 5,669
  • 5
  • 30
  • 42
  • Hm, what do you mean with the first option ("use your (div) templates")? Your markup example is exactly what I am doing, am I not? – Slauma Mar 09 '10 at 20:21
  • I am sorry. I recommend you using Repeater – garik Mar 09 '10 at 21:08
  • 2
    This does not answer the question. It is possible to tell the FormView to stop rendering as a `table` (in ASP.NET 4.0) – Kit Roed Dec 28 '10 at 21:22
  • @Kit Roed thanks for information. will learn. at that moment i had not known that. btw downvoting is a bad luck. :) and you cannot see asp.net 4.0 in tags. be more polite. – garik Dec 28 '10 at 22:30
  • Well now I feel sufficiently guilty. Update your answer and I can change my rash vote. – Kit Roed Dec 29 '10 at 16:48
  • @KitRoed: I asked the question before .NET4.0 came out. At that time it was the only answer for several months. No better solution was available before .NET4. Considering this, a downvote is not justified in my opinion. A comment pointing to the new options in .NET 4 is OK though. – Slauma Dec 12 '12 at 12:57
  • @Slauma as I said in my previous post, please update your answer to be current and the system will let me remove my downvote (and I'll likely even upvote it!) – Kit Roed Dec 12 '12 at 14:50