自定义SQL标签实现单行或单列非常方便,但是对于多行多例发现比较难实行,应用中经常用到.
通过修改kesion.Label.sqlcls.asp文件实现,主要修改二个地方;
(1)\'返回循环次数
Function GetLoopNum(Content)
Dim regEx, Matches, Match
Set regEx = New RegExp
'以下www.q311.cn添加的...2008-9-22
regEx.Pattern="\[looprow=\d*]"
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(Content)
If Matches.count > 0 Then
GetLoopNum=Replace(Replace(Matches.item(0),"[looprow=",""),"]","")
exit function
Else
GetLoopNum=0
end if
'end 取得行数
regEx.Pattern="\[loop=\d*]"
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(Content)
If Matches.count > 0 Then
GetLoopNum=Replace(Replace(Matches.item(0),"[loop=",""),"]","")
exit function 'www.q311.cn
Else
GetLoopNum=0
end if
End Function
(2)Function ReplaceDIYFunctionLabel(SqlLabel,GetFrom):
从Else
Do While Not KS_RS_Obj.Eof
For Each Match In Matches
LoopTimes=GetLoopNum(Match.Value) '循环次数
CirLabelContent = Replace(Replace(Match.value,"[loop=" & LoopTimes&"]",""),"[/loop]","")
LabelContent = Replace(LabelContent,"[loop="&LoopTimes&"]"&CirLabelContent&"[/loop]",GetCirLabelContent(CirLabelContent,KS_RS_Obj,LoopTimes),1,1)
If KS_RS_Obj.Eof Then Exit For
Next
If KS_RS_Obj.Eof Then
Exit Do
Else
KS_RS_Obj.MoveNext
End If
Loop
用以下替换:Else
' begin 以上www.q311.cn/加上去
dim Row,RowMatches,RowContent,RowLoopContent,LoopRows,M,isFound
regEx.Pattern = "\[looprow=\d*].+?\[/looprow]"
regEx.IgnoreCase = True
regEx.Global = True
isFound=regEx.Test(LabelContent) '测试有looprow行数定义
if isFound then
Set RowMatches = regEx.Execute(LabelContent)
For Each Row in RowMatches
LoopRows=GetLoopNum(Row.Value) '循环次数,
if loopRows>0 then
RowLoopContent=Replace(Replace(row.value,"[looprow=" & LoopRows&"]",""),"[/looprow]","")
else
RowLoopContent=LabelContent
LoopRows=1
end if
Next
else
RowLoopContent=LabelContent
LoopRows=1
end if '取得循环体和行数
Do While Not KS_RS_Obj.Eof
for m=1 to loopRows
regEx.Pattern = "\[loop=\d*].+?\[/loop]"
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(RowLoopContent)
For Each Match In Matches
LoopTimes=GetLoopNum(Match.Value) '列数的循环次数,
CirLabelContent = Replace(Replace(Match.value,"[loop=" & LoopTimes&"]",""),"[/loop]","")
rowContent = rowcontent&Replace(RowLoopContent,"[loop="&LoopTimes&"]"&CirLabelContent&"[/loop]",GetCirLabelContent(CirLabelContent,KS_RS_Obj,LoopTimes),1,1)
If KS_RS_Obj.Eof Then Exit For
Next
If KS_RS_Obj.Eof Then
Exit Do
Else
'KS_RS_Obj.MoveNext 由于多行时取消光标移动
End If
next
if m>looprows then '当取得的数据超过行*列数时要退出,没有用,解决?
exit do
end if
Loop
'不同的替换方法
if isFound then
LabelContent = Replace(LabelContent,"[looprow="&LoopRows&"]"&RowLoopContent&"[/looprow]",rowContent,1,1)
else
LabelContent=rowContent
end if 'end changed OK 2008-9-22 wwww.q311.cn
3\自定义SQL标签书写注意方法
列数还是由原来的[loop=]定义,由于[loop=]...[/loop]组成列的循环体,行数由[looprow=num]定义,由[looprow=num]...[/looprow]组成循环体,一般的结构由[looprow=num]..[loop=num2]...[/loop]...[/looprow];如本网站首页的博客相片就是这样完成的;{SQL_首页博客相片(6,2,3)}
SQL语句:select top {$Param(0)} AddDate,PhotoUrl,Title,UserName,xcid from KS_Photozp
最好是三个参数,显示数量,行数,列数,并且显示数量=行数*列数;
4\调用SQL标签;就OK