【发布时间】:2019-06-25 00:05:28
【问题描述】:
如果当前用户没有必要的权限,我想在RowEditing 期间取消行编辑。
这是RowEditing 的样子:
protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
string user = GetCurrentUser();
if (user == string.Empty)
{
/* Show message alert */
return;
}
GridView.EditIndex = e.NewEditIndex;
BindData();
}
这会取消更新,并且该列会继续编辑链接。但是如果我再次点击Edit,它会显示这个错误:
加载视图状态失败。正在加载视图状态的控制树必须与在先前请求期间用于保存视图状态的控制树匹配。例如,动态添加控件时,在回发期间添加的控件必须与在初始请求期间添加的控件的类型和位置相匹配。
我认为它必须在回发之前隐藏控件。
所以我的问题是,我该如何避免这种情况?
我也尝试设置GridView.EditIndex = -1,但得到相同的结果:
protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView.EditIndex = e.NewEditIndex;
BindData();
string user = GetCurrentUser();
if (user == string.Empty)
{
/* Show message alert */
GridView.EditIndex = -1;
BindData();
return;
}
【问题讨论】:
标签: c# asp.net gridview visual-studio-2013 postback