2010-06-29 55 views
0

當我使用CAML過濾我的ListView,就OK了,當我用這個CAML:當我使用CAML過濾的ListView <! - 失敗#RENDER - >是顯示在ListView

query = "<Where><Or>" + 
        "<And>" + 
         " <Eq>" + 
          "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
          "<Value Type=\"Text\">Tag</Value>" + 
         "</Eq>" + 
         "<IsNotNull>" + 
         "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
         "</IsNotNull>" + 
        "</And>" + 
        "<And>" + 
         " <Eq>" + 
          "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
          "<Value Type=\"Text\">Word</Value>" + 
         "</Eq>" + 
         "<IsNotNull>" + 
         "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
         "</IsNotNull>" + 
        "</And>" + 
        "</Or>" + 
       "</Where>"; 

它可以正常工作。

但是,當我在下面使用CAML,它會顯示錯誤在ListView

query = "<Where><Or>" + 
        "<And>" + 
         " <Eq>" + 
          "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
          "<Value Type=\"Text\">Tag</Value>" + 
         "</Eq>" + 
         "<IsNotNull>" + 
         "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
         "</IsNotNull>" + 
        "</And>" + 
        "<And>" + 
         " <Eq>" + 
          "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
          "<Value Type=\"Text\">Word</Value>" + 
         "</Eq>" + 
         "<IsNotNull>" + 
         "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
         "</IsNotNull>" + 
        "</And>" + 
        "<And>" + 
         " <Eq>" + 
          "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
          "<Value Type=\"Text\">Word Test</Value>" + 
         "</Eq>" + 
         "<IsNotNull>" + 
         "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
         "</IsNotNull>" + 
        "</And>" + 
        "</Or>" + 
       "</Where>"; 

我只是添加過濾器在第二CAML,爲什麼它不能工作?

有人可以幫忙嗎?

感謝 kedk

回答

0

您嘗試有<或者>元素中3倍的表達,但只允許正好有兩個。

所以,你必須改變:

<Or> 
    <And>...</And> 
    <And>...</And> 
    <And>...</And> 
</Or> 

<Or> 
    <Or> 
    <And>...</And> 
    <And>...</And> 
    </Or> 
    <And>...</And> 
</Or> 
0

運營商只能採取2個操作數,而不是3(不像當你在代碼中使用它)

因此,您將需要拆分查詢,或嵌套第二運營商:

"<Where><Or>" + 
       "<And>" + 
        " <Eq>" + 
         "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
         "<Value Type=\"Text\">Tag</Value>" + 
        "</Eq>" + 
        "<IsNotNull>" + 
        "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
        "</IsNotNull>" + 
       "</And>" + 
       //Nest the second part of the Query by putting another <And> here 
       "<And>" + 
        "<And>" + 
        " <Eq>" + 
         "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
         "<Value Type=\"Text\">Word</Value>" + 
        "</Eq>" + 
        "<IsNotNull>" + 
        "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
        "</IsNotNull>" + 
        "</And>" + 
        "<And>" + 
        " <Eq>" + 
         "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
         "<Value Type=\"Text\">Word Test</Value>" + 
        "</Eq>" + 
        "<IsNotNull>" + 
        "<FieldRef Name=\"TagForDiscussion\"></FieldRef>" + 
        "</IsNotNull>" + 
        "</And>" + 
       "</And>" + 
       "</Or>" + 
      "</Where>"; 
相關問題