简体   繁体   English

SharePoint 2010 - 自定义列表字段的呈现和行为

[英]SharePoint 2010 - Customizing the rendering and behavior of a List field

In my SharePoint List, I have an "Employee" column that is a User type field.在我的 SharePoint 列表中,我有一个“员工”列,它是一个用户类型字段。 I would like to add some custom Business Logic to the processing of this field.我想在该字段的处理中添加一些自定义业务逻辑。 Currently, when the user adds a row, I check to see if the user is an Employee or a Manager and then change the behavior on this column accordingly.目前,当用户添加一行时,我会检查用户是员工还是经理,然后相应地更改此列的行为。 I do this by statically rendering the field in my custom "ListForm Rendering Template", just before my custom ListFieldIterator.为此,我在我的自定义“ListForm 渲染模板”中静态渲染字段,就在我的自定义 ListFieldIterator 之前。 I simply use a standard SharePoint FormField (and FormLabel) control.我只是使用标准的 SharePoint FormField(和 FormLabel)控件。 In the markup of the FormField control, I specify the FieldName (Employee) and an event handler for the Load event.在 FormField 控件的标记中,我指定了 FieldName (Employee) 和 Load 事件的事件处理程序。 In this Load event, I will check to see if the current user is an Employee or Manager (using two different SharePoint groups).在此 Load 事件中,我将检查当前用户是 Employee 还是 Manager(使用两个不同的 SharePoint 组)。 If the user is an Employee I set the value of the field to the current user (this part works perfectly).如果用户是员工,我将字段的值设置为当前用户(这部分工作完美)。 I also want to change the field so it can't be modified.我还想更改字段,使其无法修改。 I thought I might be able to just change the ControlMode on the field (in the code of the OnLoad Event Handler) to Display, but for some reason this has no effect.我以为我可以将字段上的 ControlMode(在 OnLoad 事件处理程序的代码中)更改为 Display,但由于某种原因,这没有效果。 The field still renders with the full, people picker editor.该字段仍然使用完整的人员选择器编辑器呈现。 Am I not changing the fields control mode soon enough?我是否没有尽快更改字段控制模式? Or is this simply not the correct approach?或者这根本不是正确的方法? The other logic I want to put in is if the user is a Manager, I would like to allow that user to select the person from a list (SharePoint group) of Employees.我要输入的另一个逻辑是,如果用户是经理,我想允许该用户 select 来自员工列表(SharePoint 组)的人。 It may be easier to just use the people picker and limit the selectable users to that group.仅使用人员选择器并将可选择的用户限制在该组中可能会更容易。 (I think I can do this with the SelectionGroup property.) Although, it would be better if I could just provide a dropdownlist of users, which I could possibly do with a hidden dropdownlist that I would show and event handlers that I could use (handle event selectedindexchanged) to pull the value selected and populate the (now hidden) Employee (user) field. (我认为我可以使用 SelectionGroup 属性来做到这一点。)虽然,如果我可以提供一个用户下拉列表会更好,我可以使用我将显示的隐藏下拉列表和我可以使用的事件处理程序来做到这一点(处理事件 selectedindexchanged) 以提取选定的值并填充(现在隐藏的)员工(用户)字段。 Does this approach make sense?这种方法有意义吗? Assuming all that will work, the real difficulty I am having is with changing the ControlMode (rendering) on the field (when the user is an employee) to a label or some kind of read only control, which is how that field renders when viewing the row, which is why I think if I can just trick the control into thinking it is in Display mode then it should work perfectly!假设所有这些都可行,我遇到的真正困难是将现场(当用户是员工时)的 ControlMode(渲染)更改为 label 或某种只读控件,这是查看时该字段的呈现方式该行,这就是为什么我认为如果我可以欺骗控件使其认为它处于显示模式,那么它应该可以完美地工作!

I am still learning SharePoint, but I am very proficient in ASP.Net.我还在学习SharePoint,但是我对ASP.Net非常精通。 This is why I would like to keep my customizations in this Custom Rendering Template, using code behind and leverage my existing skill set as much as properly.这就是为什么我想在这个自定义渲染模板中保留我的自定义,使用背后的代码并尽可能地利用我现有的技能。

Any thoughts, opinions or advice?有什么想法、意见或建议吗? Does anyone know why I can't get the column to switch the "Control Mode"?有谁知道为什么我不能让专栏切换“控制模式”?

I do not think that I fully understand your scenario.我不认为我完全理解你的情况。 Some code samples could help.一些代码示例可能会有所帮助。

But anyway it sounds like you want some heavy customizations of the user field.但无论如何,听起来您想要对用户字段进行一些重度自定义。 In that case you might want to have a look at creating a custom field with all its advantages and disadvantages.在这种情况下,您可能想看看创建一个具有所有优点和缺点的自定义字段。 Have a look at MSDN: http://msdn.microsoft.com/en-us/library/gg132914.aspx看看 MSDN: http://msdn.microsoft.com/en-us/library/gg132914.aspx

Another option might be - in case you do not want to re-use this column in many list definitions - that you can get away with your custom rendering template and create a custom create/edit form where you implement the specific edit behaviour for the field (plain ASP.NET with some SharePoint controls).另一种选择可能是 - 如果您不想在许多列表定义中重复使用此列 - 您可以摆脱自定义呈现模板并创建自定义创建/编辑表单,您可以在其中实现字段的特定编辑行为(普通的 ASP.NET 和一些 SharePoint 控件)。 Here is a nice walk-through on how to grab a custom edit form from SharePoint designer: http://community.bamboosolutions.com/blogs/sharepoint-2010/archive/2011/05/12/sharepoint-2010-cookbook-how-to-create-a-customized-list-edit-form-for-development-in-visual-studio-2010.aspx这是关于如何从 SharePoint 设计师那里获取自定义编辑表单的一个很好的演练: http://community.bamboosolutions.com/blogs/sharepoint-2010/archive/2011/05/12/sharepoint-201-howbook -to-create-a-customized-list-edit-form-for-development-in-visual-studio-2010.aspx

I hope this helps.我希望这有帮助。 Kr., Bernd.克鲁,伯恩德。

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

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