2009-09-18 37 views
0

我們有一個使用搜索的Sharepoint站點。使用DataKeyname時Sharepoint搜索失敗

我們得到以下錯誤:

 
Unable to validate data. at 
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData 
(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, 
IVType ivType, Boolean useValidationSymAlgo) 
    at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) 

位測試,我們發現後,當我們使用DateKeyNames在GridView控件發生錯誤。

不知道爲什麼應該有搜索,這個錯誤和DataKeyNames之間的任何組合。

任何想法?

更新:下面是一些代碼

[Guid("8891224e-e830-4ffa-afbd-f789583d8d14")] 
    public class TestErrorGridView : System.Web.UI.WebControls.WebParts.WebPart 
    { 
     Control ascxToAdd; 
     public TestErrorGridView() 
     { 
     } 

     protected override void OnInit(EventArgs e) 
     { 
      base.OnInit(e); 

     } 

     protected override void CreateChildControls() 
     { 


      base.CreateChildControls(); 
      Table test = new Table(); 
      TestBindObject t1 = new TestBindObject() { ID = 1, Name = "Test" }; 
      List<TestBindObject> l1 = new List<TestBindObject>(); 
      l1.Add(t1); 
      SPGridView testGrid = new SPGridView() { AutoGenerateColumns = false}; 
      BoundField header = new BoundField(); 
      header.DataField = "ID"; 
      BoundField name = new BoundField(); 
      name.DataField = "Name"; 
      testGrid.Columns.Add(header); 
      testGrid.Columns.Add(name); 
      testGrid.DataSource = l1; 
      testGrid.DataBind(); 
      // If you comment out this line search works 
      testGrid.DataKeyNames = new string[] { "ID" }; 
      this.Controls.Add(testGrid); 

      base.CreateChildControls(); 
      SPGridView testGrid = new SPGridView() { AutoGenerateColumns = false, EnableViewState=false }; 

      testGrid.DataKeyNames = new string[] { "testid" }; 

      this.Controls.Add(testGrid); 

     } 
    } 

public class TestBindObject 
{ 
    public int ID { get; set; } 
    public string Name { get; set; } 
} 

UPDATE

對開發商的機器這個出現錯誤;所以它不realated機器鍵是在集羣中不同的機器不同。

其中一位開發人員安裝了MOSS,他沒有得到該錯誤。剛剛安裝WSS的開發人員會收到錯誤消息。

更新2

有數據源添加到代碼

+2

你可以發佈錯誤發生的代碼嗎? – 2009-09-18 13:35:43

+0

@Kit添加了一個代碼示例 – 2009-09-18 14:15:41

回答

0

我們最終解決了這個按照此鏈接的例子:

http://msdn.microsoft.com/en-us/library/bb466219.aspx

我認爲這是被綁定到數據表,而不是作出區別的列表。

Sharepoint網格不允許自動生成列的事實似乎是導致此問題的因素之一。

1

我要在這裏扔了一個猜測,因爲你設置GridView的數據源缺失以及代碼,但在這裏不用..

它可能與您設置GridView屬性的順序有關。我的猜測是,你需要設置順序如下:

  1. 創建你的GridView
  2. 設置GridView的數據源(使之具有數據)
  3. 設置的DataKeyNames
  4. 呼叫GridView.DataBind()

第3步和第4步是我不確定的步驟。您可能需要DataBind,然後設置DataKeyNames。

+0

感謝您的回覆,在沒有我們添加數據源的情況下發生此錯誤 – 2009-10-02 14:53:56

+0

那麼如果您沒有數據源,那麼您如何期望使用DataKeyNames屬性? – 2009-10-02 15:36:44

+0

@Kit,我們試圖剝去一切可能導致問題的東西。我用數據綁定/數據源更新了代碼。我們得到同樣的錯誤。 – 2009-10-05 09:21:04