DataFormWebPart 单列表查询

很多时候XsltListViewWebPart就已经能够满足很稳问题,

1. 但是如果你使用了 QueryString,Control等动态过滤条件后,你就会发现,即使你允许过滤和排序,过滤也已经不能在表头使用,

而是会出现:This column Type cannot be filterted.

2.其次xsltListViewWebPart当你有过滤条件设置后,而没有数据返回的时候

消息提示大概是 :There are no items in this view ,please......

3.要对自己的栏组合使用时

你就发现力不从心了,当然你也可以去自定xlst的样式,但是你会发现,远远不如DataFormWebpart方便

 

当然,使用DataFormWebPart,最大的损失我觉得是失去了 Content Menu,2007 SPD 还能做到,SPD2010就有点失望了,虽然支持 Insert as Hyperlink to New/Edit/display Form,这默认不是在新窗口打开的,更不能像2010种modal 对话框。

 

1.创建DataFromWebPart

SPD打开页面,切换到split

 SPD2010-->Insert-->DataView-->Empty Data View

2.选择数据源

点击设计窗口的 clice here to select a data source.

选择你需要的List,Library.

 3.定义栏

   下面介绍几种常用的

   File Type的图标显示   

< IMG  BORDER ="0"  ALT ="{@FileLeafRef}"  title ="{@FileLeafRef}"  SRC ="/_layouts/images/{ddwrt:MapToIcon(string(@HTML_x005F_x0020_File_x005F_x0020_Type),string(@File_x005F_x0020_Type))}"   />

  连接到文件的Title 

  < href ="{concat(@ServerUrl,substring-after(@FileRef,';#'))}" >
                    
< xsl:attribute  name ="target" >
                    _blank
                    
</ xsl:attribute >              
                    
< xsl:attribute  name ="onclick" >
                          
< xsl:value-of  select ="@OnClickTargetAttribute" />
                    
</ xsl:attribute >
                    
< xsl:value-of  select ="substring-after(@FileLeafRef,';#')" />
 
</ a >

 下面是最为关键的链接到编辑页面的Edit,弹出对话框,并能提交时候刷新父页面,很帅的

 ListID为要显示的List的ID,

 PageType为页面类型,4是DisplayForm.aspx,6是EditForm.aspx

 ContentTypeId就不多说了

 ID 就是Item的ID 

 这个 /_layouts/listform.aspx地址要根据实际的环境骚有变化,

 如果网站是 sites/mysite/形式,可能需要变为 ../layouts/listform.aspx

< a >
  
< xsl:attribute  name ="href" > # </ xsl:attribute >
  
< xsl:attribute  name ="onclick" >
    
< xsl:text > javascript:NewItem2(event, &quot; /_layouts/listform.aspx?PageType=6 &amp; ListId={E0A88D76-869A-44DA-8F6E-FF59182D3CC4} &amp; ContentTypeId= </ xsl:text >
    
< xsl:value-of  select ="@ContentTypeId"   />
    
< xsl:text > &amp; ID= </ xsl:text >
    
< xsl:value-of  select ="@ID"   />
    
< xsl:text > &amp; RootFolder= &quot; );javascript:return false; </ xsl:text >
  
</ xsl:attribute >
  
< xsl:attribute  name ="target" >
    _blank
  
</ xsl:attribute >
  Edit
</ a >

 

你使用DataFormWebPart之后,默认是不支持排序和过滤的

你选中DataFormWebpart之后,SPD2010头部Tab的Desgin区域选中Sort & Filter on Headers

你在Design的设计面板中(不是头部Tab区域)选中任意栏的和header,大致的内容如下

filedname是过滤和排序的InnerName,sortable为1表示为1,fieldtype格式一定要为x:形式,要注意了

< xsl:call-template  name ="dvt.headerfield"  ddwrt:atomic ="1"  xmlns:ddwrt ="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" >
                            
< xsl:with-param  name ="fieldname" > @Project_x0020_Status </ xsl:with-param >
                            
< xsl:with-param  name ="fieldtitle" > Project Status </ xsl:with-param >
                            
< xsl:with-param  name ="displayname" > Project Status </ xsl:with-param >
                            
< xsl:with-param  name ="sortable" > 1 </ xsl:with-param >
                            
< xsl:with-param  name ="fieldtype" > x:string </ xsl:with-param >
                        
</ xsl:call-template >

 

并自定义栏后,

1.你会发现,即使QueryString,Control等动态过滤条件后,任然可以进行过滤,真的是很帅气

2.自定义后的编辑链接也很帅气了,不会直接的跳转,

3.还可以自定义 消息了,

找到如下的,更换内容就ok了。

<xsl:variable name="dvt_ViewEmptyText">There are no items to show in this view.</xsl:variable> 

 

 相关参考资料:

http://www.kurtopel.com/2010/08/linking-to-sharepoint-2010-list-forms/

http://www.chakkaradeep.com/post/Using-the-SharePoint-2010-Modal-Dialog.aspx

 

你可能感兴趣的:(form)