使用DataKeyName时Sharepoint搜索失败

使用DataKeyName时Sharepoint搜索失败,sharepoint,search,gridview,moss,wss,Sharepoint,Search,Gridview,Moss,Wss,我们有一个使用搜索的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)

我们有一个使用搜索的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) 经过一点测试,我们发现在GridView控件上使用DateKeyNames时会发生错误

不确定为什么搜索、此错误和DataKeyName之间应该有任何组合

有什么想法吗

更新:这里有一些代码

[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; }
}
更新

此错误发生在开发人员的机器上,因此不适用于集群中不同机器上的机器密钥不同

其中一个开发人员安装了MOSS,但他没有收到错误。刚安装WSS的开发人员会收到错误

更新2


在代码中添加了数据源

我想在这里抛出一个猜测,因为您设置GridView数据源的代码也丢失了,但是下面是

它可能与设置GridView属性的顺序有关。我猜您需要按以下顺序设置:

创建您的GridView 设置GridView的数据源,使其具有数据 设置DataKeyName 调用GridView.DataBind
步骤3和步骤4是我不确定的步骤。您可能需要进行数据绑定,然后设置DataKeyName。

我们最终通过以下链接中的示例解决了此问题:

我认为这是绑定到一个数据表而不是一个列表的结果


Sharepoint网格不允许自动生成列这一事实似乎是导致此问题的因素之一

你能在错误发生的地方发布代码吗?@Kit已经添加了一个代码样本谢谢你的回复,这个错误是在我们没有添加数据源的情况下发生的。如果你没有数据源,你怎么能期望使用DataKeyNames属性呢?@Kit,我们试图去除所有可能导致问题的东西。我已经用数据绑定/数据源更新了代码。我们得到了相同的错误。+1感谢您的帮助,我们最终改为使用DataTables