EditItemTemplate 및 InsertItemTemplate이 포함 된 ListView가 있습니다. 이 두 형식은 거의 모든 마크 업을 공유합니다. 예를 들어 :EditItemTemplate 및 InsertItemTemplate에서 동일한 태그가있는 ASP.NET ListView
물론<asp:listview runat="server" ... >
<layouttemplate>...</layouttemplate>
<itemtemplate>
<p><%#Eval("Name")%></p>
<p><%#Eval("Title")%></p>
...
</itemtemplate>
<insertitemtemplate>
<p>Name: <asp:textbox runat=server text='<%#Bind("Name")%>' /></p>
<p>Title: <asp:textbox runat=server text='<%#Bind("Title")%>' /></p>
...
<asp:button runat=server commandname="Insert" text="Save" />
</insertitemtemplate>
<edititemtemplate>
<p>Name: <asp:textbox runat=server text='<%#Bind("Name")%>' /></p>
<p>Title: <asp:textbox runat=server text='<%#Bind("Title")%>' /></p>
...
<asp:button runat=server commandname="Update" text="Save" />
</edititemtemplate>
</asp:listview>
는 실제로 삽입 및 편집 템플릿 (서식, 검증 등으로 분야를 많이,) 진행이 많이있다, 그리고 나는 같은 마크 업을 유지하기가 싫어 두번.
<insertitemtemplate>
<custom:myform runat=server />
<asp:button runat=server commandname="Insert" text="Save" />
</insertitemtemplate>
<edititemtemplate>
<custom:myform runat=server />
<asp:button runat=server commandname="Update" text="Save" />
</edititemtemplate>
불행하게도, 양방향 바인딩 (텍스트 = '<퍼센트 번호 바인드 ("푸") :
내 첫번째 생각은 사용자 컨트롤 (의 .ascx)에 모든 공유 마크 업을 이동했다 %> ')는 폼이 사용자 정의 컨트롤에있을 때만 한 방향으로 작동합니다 (컨트롤의 데이터를 다시 데이터베이스에 유지하지 않음).
다른 대안은 모든 공유 마크 업을 포함 파일로 이동하는 것입니다. 서버 측 포함은 고전적인 ASP에 대한 후퇴이지만 ASP.NET에서 여전히 작동하며 이와 같은 상황에서 유용 할 수 있습니다. 포함 파일의 내용이 페이지에 표시된 것과 같이 취급되기 때문입니다.
그러나 포함 파일은 여전히 조금 혼란스럽고 단점이 있습니다 (예 : VisualStudio는 그다지 익숙하지 않습니다). 대안이 있습니까?
이 게시물에 따르면 : 'http : // forums.asp.net/p/1344635/2729853.aspx', 선언적으로하는 것은 매우 까다 롭습니다. 코드 숨김에서 템플릿을 만드는 것이 더 쉬울 것입니다. – keyboardP