Customizing SharePoint 2007 List Forms (DispForm.aspx, NewForm.aspx, EditForm.aspx)

[Updated Feb 27, 2008] It's important to note that customizing forms breaks attachment support! If you're going to be attaching documents to these list items you will either need to write code to upload the attachments yourself or NOT customize the form. This is still not fixed with SP1.
When you create a new list in SharePoint, a default form for viewing, editing and adding are provisioned for you by SharePoint. This is also true for any views that you define on the list. SharePoint creates an .aspx page at http://siteroot/Lists/ListName/DispForm.aspx. You can see all these pages using the SharePoint Designer.


Be default they are basically a WebPartZone with a ListFormWebPart inside.

The real story though is that you can customize these lists. Not only can you very easily create your own, but you can tell the list to always use your form. You can even tell the list to use your form for certain Content Types (if the list has multiples) and use the default Form for other Content Types.

Creating a Custom List

In the following example we're going to create a new Form for adding contacts, then we'll have SharePoint Designer change it so that it can use the current master page and participate in any branding effort you may be doing.

  1. Right click on the list (ie. Contacts) then go to New->ASPX.
  2. Rename the form to something that makes sense (ie. NewContact.aspx)
  3. Now we need to turn this blank form into a page that can view content from the list. Double click on the form. Once it's in focus in SharePoint Designer on the toolbar click Insert->SharePoint Controls->Custom List Form (see below). In the popup choose your list (ie. Contacts) and the type of form you want to customize (ie. NewForm). Notice that you can also choose a Content Type to customize the forms for. You can literally have a separate customized 'NewForm' for each Content Type that the list stores. Click Ok and watch as your form gets automagically tee'd up with all the controls it needs allow users to add Contacts to the list.

  4. Now that we have a form that can add new Contacts, lets make sure it enforces our brand by attaching a Master Page. Click Format->Master Page->Attach Master Page. Choose the 'Default Master Page' and watch SharePoint Designer neatly place all the markup that matters inside of a ContentPlaceHolder and attach the current runtime master page.
  5. Ok our last step, we need to tell our list to use our new customized form. Right click on the list in question. Click 'Properties'. Click on the 'Supporting Files' tab and then change the 'New item form' to the .aspx you just made. It's of note that the .aspx needs to be housed inside the list, you can't just house it anywhere.
  6. You're done, head back to your contacts list (in SharePoint and add a new item, you'll see the form that we just made). You can of course do the same for DispForm.aspx and EditForm.aspx.

Here's a screen shot of some text that we changed on the form. Future posts will get into actually working with SharePoint controls and putting a code behind on the form, so you can write some C# to alter the behavior of this form (in addition to changing the declarative markup in this .aspx).

Ok, that's it for now. Good luck.

(Source:blog.tylerholmes.com)

1 nhận xét:

NHACF.COM said...

Bạn có biết, với blogspot của google bạn có thể làm mọi thứ bạn muốn! Blogspot với nhiều ưu điểm mà hầu hết các webmaster đều phải công nhận. Nó hoàn toàn miễn phí, lưu trữ ổn định lâu dài, tốc độ khá nhanh và truy cập được mọi nơi trên thế giới, bảo mật cao chống được các kỹ thuật hack mà không hosting nào có thể sánh bằng! Vì vậy blog của bạn tạo ra sẽ đc lưu trữ mãi mãi trên internet, không như các blog khác của vn, bảo trì mà không hẹn ngày hoàn thành phí biết bao nhiêu công sức của bạn.

Vì vậy hãy giới thiệu với mọi người để cộng đồng blogger của vn ngày càng phát triển.

Mới đầu dùng có thể bạn thấy giao diện của nó không đẹp, nhưng trên internet có rất nhiều template được chia sẻ, bạn chỉ cần copy nó bỏ vào Edit HTML, blog của bạn sẽ rất đẹp và chuyên nghiệp hơn.

Bạn cũng có thể đổi tên tenban.blogspot.com thành tenban.com chỉ cần 180k/năm để mua tên miền.

Có rất nhiều webmaster muốn biến blog này thành website lớn, bạn chỉ cần biết ngôn ngữ web, bạn có thể viết bất kỳ thứ gì bạn muốn trong nó.

Đây là trang web của mình cũng dùng blogspot. Nghe Nhạc Pro - Phong Cách & Đẳng Cấp Chuyên Nghiệp, bạn cũng có thể tạo 1 trang giống như thế ở đây code nhạc .

Mình thích dùng blog của google và muốn giới thiệu với các bạn. để có nhiều người Việt dùng hơn, mọi người sẽ hay vào blog của nhau hơn..

Chúc blog của bạn ngày càng phát triển và hay hơn nữa!!

Post a Comment

thanks comment