无法加载viewstate。 GridView中的DropDownList

时间:2013-12-22 00:50:10

标签: asp.net

DropDownList添加EditItemTemplate时出现此错误:

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.

我正在对RowDataBound事件中的代码进行绑定。如何在此处正确添加此控件?

1 个答案:

答案 0 :(得分:0)

尝试将数据绑定到gridview,只有当它不是回传时,

....
protected void Page_Load(object sender, EventArgs e)
{
...
       If(!Page.IsPostBack)
       {
             ......
             gridview.DataBind();
             .....
       }
...
}