简体   繁体   English

自定义Webpart中的SharePoint:FormField?

[英]SharePoint:FormField in a custom webpart?

On my home page, I want a simple webpart that allow users to quickly fill an entry in a list. 在我的主页上,我需要一个简单的Web部件,该部件允许用户快速填写列表中的条目。

The list have, let's say, three fields : title (text), body (rich text), category (lookup). 假设该列表具有三个字段:标题(文本),正文(富文本),类别(查找)。

I don't want to use the standard DataFormWebPart because I have a bit of code-behind that also fill some technical hidden fields of my list (actually, I don't exclude the DataFormWebPart, but I didn't find how to use it with code behind). 我不想使用标准的DataFormWebPart,因为我后面有一些代码,它们也填充了列表中的一些技术隐藏字段(实际上,我不排除DataFormWebPart,但我没有找到如何使用它的方法)后面有代码)。

So I started to implement a custom webpart. 因此,我开始实现自定义Webpart。 Because I don't want to have to handle manually each field input, I started to use the FormField control, which automatically choose the rendering control, and provide a Value property with the correct format : 因为我不想手动处理每个字段输入,所以我开始使用FormField控件,该控件自动选择呈现控件,并提供具有正确格式的Value属性:

<SharePoint:FormField runat="server" id="fldTitle" FieldName="Title" />

This code is not sufficient, I have to specified the listid : 这段代码还不够,我必须指定listid:

<SharePoint:FormField runat="server" id="fldTitle" FieldName="Title" ListId="{title list guid}" />

This is working quite correctly. 这很正常。 I can in code access the fldTitle.Value to retrieve the user input. 我可以在代码中访问fldTitle.Value来检索用户输入。

BUT I have to include the webpart in a properly packaged and deployed feature, that can be activated. 但是我必须将Webpart包含在正确打包和部署的功能中,然后才能激活该功能。 The webpart will always target the same list, but as the list is also instanciated in the feature (ListInstance element), I can't know the Guid in advance. Webpart将始终以同一列表为目标,但是由于该列表也在功能部件(ListInstance元素)中得到了实例化,因此我无法提前知道Guid。

I've tried using several technics to set the list ID on the fly, but without success. 我尝试使用多种技术即时设置列表ID,但没有成功。

I've also "reflectored" the SP dlls to notice FormComponent class are using a "Context" that is set by ListFormWebPart. 我还“反射”了SP dll以注意到FormComponent类正在使用由ListFormWebPart设置的“上下文”。

Finally, my questions are : 最后,我的问题是:

  • is it the correct way to create a custom input webpart on the home page (not a list custom form) ? 这是在主页上创建自定义输入Web部件(而不是列表自定义表单)的正确方法吗?
  • how can I keep the behavior of the FormField (choose the right control and handle the input and its conversion to the storage format) ? 如何保持FormField的行为(选择正确的控件并处理输入并将其转换为存储格式)?
  • Will I have to create a custom ListFormWebPart ? 我将必须创建一个自定义ListFormWebPart吗?
  • May I play with ControlTemplates ? 我可以玩ControlTemplates吗?

thanks in advance for the help... I'm struggling with this simple case for days now... 在此先感谢您的帮助...我已经为这个简单的案例苦苦挣扎了好几天了...

I think that customizing form templates is the easiest way to customize list forms. 我认为自定义表单模板是自定义列表表单的最简单方法。 Since custom form templates are implemented as user controls you can add whatever code you want. 由于自定义表单模板是作为用户控件实现的,因此您可以添加所需的任何代码。 See the following article: http://www.codeproject.com/KB/sharepoint/SharePointListForms.aspx 请参阅以下文章: http : //www.codeproject.com/KB/sharepoint/SharePointListForms.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM