SharePoint:扩展DVWP - 第2部分:布局增强 – 在插入模板中重新排列栏
在上一篇博文中,我们在DVWP中将编辑/删除链接从左侧一道右侧。如果我们在DVWP中启用了插入链接,我们也需要在插入模板中做同样的事情。
1、切换视图
切换到插入模板,可以通过点击右上角的右尖括号图标(通过在设计视图中将鼠标移到该webpart上时显示出来)。
选择插入模板进行预览
可以肯定的是,它会像编辑模板一样错了位:
2、找到该模板
这时,我们找一个名为dvt_1.rowinsert的模板。在设计视图中点击一个字段(只要不是保存/取消链接就行)以便在代码视图中定位该模板:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | < xsl:template name="dvt_1.rowinsert"> < xsl:param name="IsInsertMode" /> < xsl:variable name="Pos">_new</ xsl:variable > < tr > < xsl:choose > < xsl:when test="$IsInsertMode = '1'"> < xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1"> < td class="ms-vb" width="1%" nowrap="nowrap"> < xsl:call-template name="dvt_1.automode"> < xsl:with-param name="KeyField">ID</ xsl:with-param > < xsl:with-param name="KeyValue" select="ddwrt:EscapeDelims(string(@ID))" /> < xsl:with-param name="Mode">insert</ xsl:with-param > </ xsl:call-template > </ td > </ xsl:if > < td class="ms-vb"> < SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="New" FieldName="Title" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}" /> < SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="Title" ControlMode="Edit" /> </ td > < td class="ms-vb"> < xsl:value-of select="@Editor" disable-output-escaping="yes" /> </ td > < td class="ms-vb"> < xsl:value-of select="ddwrt:FormatDate(string(@Modified),2052, 5)" /> </ td > </ xsl:when > < xsl:otherwise > < td class="ms-vb" colspan="99"> < a href="javascript: {ddwrt:GenFireServerEvent('__cancel;dvt_1_form_insertmode={1}')}">插入</ a > </ td > </ xsl:otherwise > </ xsl:choose > </ tr > </ xsl:template > |
3、编辑该模板
同样,我们将该模板的调用移到整段内容底部,以便使其在列表最右侧显示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | < xsl:template name="dvt_1.rowinsert"> < xsl:param name="IsInsertMode" /> < xsl:variable name="Pos">_new</ xsl:variable > < tr > < xsl:choose > < xsl:when test="$IsInsertMode = '1'"> < td class="ms-vb"> < SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="New" FieldName="Title" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}" /> < SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="Title" ControlMode="Edit" /> </ td > < td class="ms-vb"> < xsl:value-of select="@Editor" disable-output-escaping="yes" /> </ td > < td class="ms-vb"> < xsl:value-of select="ddwrt:FormatDate(string(@Modified),2052, 5)" /> </ td > < xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1"> < td class="ms-vb" width="1%" nowrap="nowrap"> < xsl:call-template name="dvt_1.automode"> < xsl:with-param name="KeyField">ID</ xsl:with-param > < xsl:with-param name="KeyValue" select="ddwrt:EscapeDelims(string(@ID))" /> < xsl:with-param name="Mode">insert</ xsl:with-param > </ xsl:call-template > </ td > </ xsl:if > </ xsl:when > < xsl:otherwise > < td class="ms-vb" colspan="99"> < a href="javascript: {ddwrt:GenFireServerEvent('__cancel;dvt_1_form_insertmode={1}')}">插入</ a > </ td > </ xsl:otherwise > </ xsl:choose > </ tr > </ xsl:template > |
4、检查显示效果
由于我们编辑了代码,所以当我们回到设计视图时,会重新跳回默认值模板。当我们切回到插入模板后,会看到如下图所示的效果:
目标达成。用于插入操作的链接移到DVWP的右侧。
插入模板最终的页面布局如下图所示:
插入模板:
默认模板:
接下来的扩展DVWP文章中,我们将讨论如何将操作链接转成按钮。
参考资料
SharePoint: Extending the DVWP – Part 2: Layout Enhancement – Rearranging Columns – Insert Template
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!