我有许多类似结构的 FormView。为了避免重复标记,我创建了一个包含 FormView 的母版页,并在 FormView 中放置了一个 ContentPlaceHolder。特定的数据绑定控件——这是唯一在页面之间发生变化的东西——然后位于使用该母版页的页面上。
所以我有一个看起来像这样的母版页:
<%@ master ... %>
...
<form runat=server>
...
<asp:formview runat="server" ... >
<edititemtemplate>
... Lots of common markup ...
<asp:contentplaceholder id='FormRows' runat='server' />
... Lots more common markup ...
</edititemtemplate>
</asp:formview>
...
</form>
以及使用该母版页的页面,如下所示:
<%@ page masterpagefile="Form.Master" ... %>
<asp:content contentplaceholderid="FormRows" runat="server" >
...
<p>
Field One:
<asp:textbox runat=server text='<%#Bind("Field1")%>' id='Field1' />
</p>
<p>
Field Two:
<asp:textbox runat=server text='<%#Bind("Field2")%>' id='Field2' />
</p>
...
</asp:content>
使用现有记录,FormView 可以看到数据绑定控件(Field1 等)并用正确的数据填充它们。但是在插入或更新时,它看不到它们,并且它们不包含在插入或更新中。在FormView_ItemInserting
事件中,e.Values
是空的;同样在FormView_ItemUpdating
事件中,e.NewValues
是空的。
所以:
有没有办法让母版页上的 FormView 看透 ContentPlaceholder 内的数据绑定控件?
如果做不到这一点,是否有一种直接的方法来识别数据绑定的控件,
<%#Bind(...)%>
以便我可以手动将它们添加到值包中?