2009-09-18 66 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