修改 FormView 的默认模板

发布于 2024-10-16 05:31:33 字数 969 浏览 3 评论 0原文

我经常使用 FormView 控件,但我希望对默认模板有更多的控制权。

当我将 FormView 从工具箱拖到页面上并将其指向 DataSource 控件时,它会预先填充 ItemTemplate、EditItemTemplate 和 InsertItemTemplates,但效果不是很好。

例如,InsertItemTemplate 默认情况下看起来像这样:

<InsertItemTemplate>
id:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("id") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
...
</InsertItemTemplate>

但我更喜欢的是一个好的老式 html 表

<InsertItemTemplate>
<table>
 <tr>
   <td>
     id:
   </td>
   <td>
    <asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("id") %>' />
    </td>
  <tr>
  ...
</table>
</insertItemTemplate>

我知道我可以使用 DetailsView 来获取呈现的表,但我最终对表单进行了太多修改,以至于我更喜欢使用表单视图。只是我希望 Visual Studio 让我更接近我想要的最终目标。

我想象 VS 内部有一个 T4 模板,我可以修改它来完成这项工作。

有人遇到过这种事吗?

I use the FormView control quite a bit, but I wish I had more control over the default templates.

When I drag a FormView from the toolbox onto my page and point it to a DataSource control it prepopulates the ItemTemplate, EditItemTemplate and InsertItemTemplates, but it doesn't do it very well.

For example, the InsertItemTemplate looks like this by default:

<InsertItemTemplate>
id:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("id") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
...
</InsertItemTemplate>

But what I would prefer is a good old fashioned html table

<InsertItemTemplate>
<table>
 <tr>
   <td>
     id:
   </td>
   <td>
    <asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("id") %>' />
    </td>
  <tr>
  ...
</table>
</insertItemTemplate>

I know I can use a DetailsView to get a table rendered out, but I end up modifying the form so much that I prefer to use the FormView. It's just that I would like Visual Studio to start me out a bit closer to where I want to end up.

I would imagine that there is a T4 template somewhere in the guts of VS that I might be able to modify to get this done.

Anybody had any luck with this kind of thing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事还在继续 2024-10-23 05:31:33

哇,有趣的问题,但我不认为它是可修改的或 T4 模板;我个人认为该控件是在FormView的控件设计器中实现的。这些类型的设计时设置可以出现在那里。不幸的是,设计时框架中的许多功能都不能像这样自定义,除非您有第三方插件。

但是,您也许可以通过代码片段实现您想要做的事情,如下所示: http://vbcity.com/blogs/mike-mcintyre/archive/2009/02/03 /visual-studio-2010-net-4-0-snippets-in-aspx-page-markup.aspx

Wow interesting question, but I don't think it is modifiable or a T4 template; I personally think its in the FormView's control designer that the control implements. These types of design-time settings can be present there. Unfortunately, a lot of the features within the design-time framework aren't customizable like that, unless you have a third-party plugin.

However, you may be able to achieve what you are looking to do through a snippet, as depicted here: http://vbcity.com/blogs/mike-mcintyre/archive/2009/02/03/visual-studio-2010-net-4-0-snippets-in-aspx-page-markup.aspx

梦过后 2024-10-23 05:31:33

如果您在 Visual Studio 的可视化编辑器中单击控件本身,会出现一个小箭头,单击该箭头,然后有一个选项可以停止使用默认模板。

很抱歉说得含糊,但我的家用电脑上没有 Visual Studio

If you click the control itself within visual editor of visual studio, there is a little arrow, click that and there is an option there to stop using the default template.

Sorry to be vague, but I don't have Visual Studio on my home PC

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文