Telerik RadGrid-编辑时过滤不记得正确的行
我已经实现了一个具有编辑和插入模式以及过滤功能的RadGrid 在编辑模式下过滤RadGrid时,编辑的行似乎基于行号,例如,当我编辑第3行时,网格被过滤,即使我当前编辑的记录行可能已更改,编辑的行仍保留在第3行 例如,如果我正在使用就地编辑在此表上执行自动CRUD (id) (code) ----------------------- (01) codeX (02) codeY (03) codeY (id)(代码) ----------------------- (01)法典 (02)科迪 (03)科迪 正在编辑的行是第二行((02)codeY) 如果对代码“EqualTo”‘codeY’执行过滤器(使用RadGrid默认过滤器),则结果为 (id) (code) ----------------------- (02) codeY (03) codeY (id)(代码) ----------------------- (02)科迪 (03)科迪 编辑的行仍然是第二行((03)代码),即使最初正在编辑的行是((02)代码)Telerik RadGrid-编辑时过滤不记得正确的行,telerik,radgrid,Telerik,Radgrid,我已经实现了一个具有编辑和插入模式以及过滤功能的RadGrid 在编辑模式下过滤RadGrid时,编辑的行似乎基于行号,例如,当我编辑第3行时,网格被过滤,即使我当前编辑的记录行可能已更改,编辑的行仍保留在第3行 例如,如果我正在使用就地编辑在此表上执行自动CRUD (id) (code) ----------------------- (01) codeX (02) codeY (03) codeY (id)(代码) ----------------------- (01)法典 (02)科迪
这是预期的行为,还是有方法指示RadGrid查找记录以再次设置该特定记录的编辑模式?如果没有,是否有办法在筛选之前自动取消编辑模式/插入模式?或者在用户处于编辑/插入模式时禁用所有筛选控件?谢谢你的阅读 请尝试以下代码片段 ASPX
ASPX.CS
public List<int> EditIDs
{
get
{
if (ViewState["EditID"] != null)
{
return (List<int>)ViewState["EditID"];
}
else
{
return new List<int>();
}
}
set { ViewState["EditID"] = value; }
}
public bool IsFilterCommandFire { get; set; }
protected void Page_Init(object sender, EventArgs e)
{
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
EditIDs = new List<int>();
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data = new[] {
new { ID = 1, Name ="Name1"},
new { ID = 2, Name = "Name2"},
new { ID = 3, Name = "Name3"},
new { ID = 4, Name = "Name4"},
new { ID = 5, Name = "Name5"},
new { ID = 26, Name = "Name26"}
};
RadGrid1.DataSource = data;
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName)
{
IsFilterCommandFire = true;
}
else if (e.CommandName == RadGrid.EditCommandName)
{
int ID = Convert.ToInt32((e.Item as GridEditableItem).GetDataKeyValue("ID"));
EditIDs.Add(ID);
}
else if (e.CommandName == RadGrid.CancelCommandName)
{
int ID = Convert.ToInt32((e.Item as GridEditableItem).GetDataKeyValue("ID"));
EditIDs.Remove(ID);
}
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
if (IsFilterCommandFire)
{
foreach (GridDataItem item in RadGrid1.Items)
{
if (EditIDs.Contains(Convert.ToInt32(item.GetDataKeyValue("ID"))))
{
item.Edit = true;
}
else
{
item.Edit = false;
}
}
RadGrid1.Rebind();
}
}
公共列表EditIDs
{
得到
{
if(ViewState[“EditID”]!=null)
{
返回(列表)视图状态[“编辑ID”];
}
其他的
{
返回新列表();
}
}
设置{ViewState[“EditID”]=value;}
}
公共bool IsFilterCommandFire{get;set;}
受保护的无效页_Init(对象发送方,事件参数e)
{
}
受保护的无效页面加载(对象发送方、事件参数e)
{
如果(!IsPostBack)
{
EditIDs=新列表();
}
}
受保护的无效页面\u预呈现(对象发送方,事件参数e)
{
}
受保护的void RadGrid1_NeedDataSource(对象发送方,GridNeedDataSourceEventArgs e)
{
动态数据=新[]{
新的{ID=1,Name=“Name1”},
新的{ID=2,Name=“Name2”},
新的{ID=3,Name=“Name3”},
新的{ID=4,Name=“Name4”},
新的{ID=5,Name=“Name5”},
新的{ID=26,Name=“Name26”}
};
RadGrid1.DataSource=数据;
}
受保护的void RadGrid1_ItemCommand(对象发送方,GridCommandEventArgs e)
{
如果(e.CommandName==RadGrid.FilterCommandName)
{
IsFilterCommandFire=true;
}
else if(e.CommandName==RadGrid.EditCommandName)
{
int ID=Convert.ToInt32((如GridEditableItem.GetDataKeyValue(“ID”));
EditIDs.Add(ID);
}
else if(e.CommandName==RadGrid.CancelCommandName)
{
int ID=Convert.ToInt32((如GridEditableItem.GetDataKeyValue(“ID”));
EditIDs.Remove(ID);
}
}
受保护的void RadGrid1_预渲染(对象发送方,事件参数e)
{
如果(IsFilterCommandFire)
{
foreach(RadGrid1.Items中的GridDataItem项)
{
if(EditIDs.Contains(Convert.ToInt32(item.GetDataKeyValue(“ID”)))
{
item.Edit=true;
}
其他的
{
item.Edit=false;
}
}
RadGrid1.Rebind();
}
}
如果有任何问题,请告诉我。没有任何此类内置功能。请告诉我您想保持可编辑模式或删除过滤器上的可编辑模式。因此,我将根据您的要求提供示例代码。谢谢Jayesh,它非常有效。我把你的建议和普林西的建议结合起来了()。无论如何,我很好奇为什么这个特性(过滤时记住编辑行的能力)没有自动添加到控件中?将来会增加吗?
public List<int> EditIDs
{
get
{
if (ViewState["EditID"] != null)
{
return (List<int>)ViewState["EditID"];
}
else
{
return new List<int>();
}
}
set { ViewState["EditID"] = value; }
}
public bool IsFilterCommandFire { get; set; }
protected void Page_Init(object sender, EventArgs e)
{
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
EditIDs = new List<int>();
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data = new[] {
new { ID = 1, Name ="Name1"},
new { ID = 2, Name = "Name2"},
new { ID = 3, Name = "Name3"},
new { ID = 4, Name = "Name4"},
new { ID = 5, Name = "Name5"},
new { ID = 26, Name = "Name26"}
};
RadGrid1.DataSource = data;
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName)
{
IsFilterCommandFire = true;
}
else if (e.CommandName == RadGrid.EditCommandName)
{
int ID = Convert.ToInt32((e.Item as GridEditableItem).GetDataKeyValue("ID"));
EditIDs.Add(ID);
}
else if (e.CommandName == RadGrid.CancelCommandName)
{
int ID = Convert.ToInt32((e.Item as GridEditableItem).GetDataKeyValue("ID"));
EditIDs.Remove(ID);
}
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
if (IsFilterCommandFire)
{
foreach (GridDataItem item in RadGrid1.Items)
{
if (EditIDs.Contains(Convert.ToInt32(item.GetDataKeyValue("ID"))))
{
item.Edit = true;
}
else
{
item.Edit = false;
}
}
RadGrid1.Rebind();
}
}