Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从web用户控件加载视图状态错误_C#_Radgrid - Fatal编程技术网

C# 无法从web用户控件加载视图状态错误

C# 无法从web用户控件加载视图状态错误,c#,radgrid,C#,Radgrid,我在web用户控件中为Telerik RadGrid设置了一些默认属性,如排序等,然后在aspx页面上使用此用户控件。网格完美地显示了数据,但当我单击排序时,它会出现以下错误 Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous re

我在web用户控件中为Telerik RadGrid设置了一些默认属性,如排序等,然后在aspx页面上使用此用户控件。网格完美地显示了数据,但当我单击排序时,它会出现以下错误

Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
这是我的用户控制代码

  [ToolboxData("<{0}:CustomRadGrid runat=server> </{0}:CustomRadGrid>")]
    public class CustomRadGrid : RadGrid
    {


        RadGrid radgrid;
        public override bool AllowSorting
        {
            get
            {
                bool o = Convert.ToBoolean(ViewState["Text"]);
                return radgrid.AllowSorting != false ? true : true;
            }
            set
            {
                EnsureChildControls();
                if (value != null)
                {
                    ViewState["Text"] = value;
                }
            }
        }
        protected override void CreateChildControls()
         {
             Controls.Clear();
            radgrid = new RadGrid();
            //radgrid.AllowSorting = true;
            radgrid.AllowFilteringByColumn = true;
            radgrid.Width = Unit.Percentage(100);
            radgrid.ExportSettings.ExportOnlyData = true;
            radgrid.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;
            this.Controls.Add(radgrid);
        }




        public CustomRadGrid()
        {
            //
            // TODO: Add constructor logic here
            //
        }
    }
[ToolboxData(“”)
公共类CustomRadGrid:RadGrid
{
雷达栅格;
公共覆盖布尔允许排序
{
得到
{
bool o=Convert.ToBoolean(视图状态[“文本]);
return radgrid.AllowSorting!=false?true:true;
}
设置
{
ensureChildControl();
if(值!=null)
{
ViewState[“文本”]=值;
}
}
}
受保护的覆盖无效CreateChildControls()
{
控件。清除();
radgrid=新的radgrid();
//radgrid.AllowSorting=true;
radgrid.AllowFilteringByColumn=true;
radgrid.宽度=单位百分比(100);
radgrid.ExportSettings.ExportOnlyData=true;
radgrid.ExportSettings.Excel.Format=GridExcelExportFormat.ExcelML;
this.Controls.Add(radgrid);
}
公共CustomRadGrid()
{
//
//TODO:在此处添加构造函数逻辑
//
}
}
控件是aspx中的外接程序:

<customRadGrid:CustomRadGrid runat="server" ID="sa" DataSourceID="SqlDataSource1" AllowSorting="true" AutoGenerateColumns="false"> 
    <MasterTableView> 
        <Columns> 
              <telerik:GridBoundColumn DataField="EmpID" HeaderText="Employeeid ID">  
              </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Name" HeaderText="Name"></telerik:GridBoundColumn>                
              <telerik:GridBoundColumn DataField="Salary" HeaderText="Salary"></telerik:GridBoundColumn>
        </Columns> 
    </MasterTableView> 
</customRadGrid:CustomRadGrid>

我已经尽了一切努力来解决这个问题,如果有人有想法,请帮忙。
提前感谢。

是否动态添加此控件以及添加位置。我只是在aspx页面添加它,我的意思是不动态添加。您是否尝试将EnableViewState=“false”添加到您的gridyes,当我设置EnableViewState=“fasle”时。它会出现以下错误。无法将“System.Collections.ArrayList”类型的对象强制转换为“System.Collections.Hashtable”类型