RadControls for ASP.NET Ajax 笔记(1)
(1)遍历Grid中的所有Item(一行),一次仅展开一行【Single expand in hierarchical grid】
private void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
if(e.CommandName == RadGrid.ExpandCollapseCommandName)
{
foreach(GridItem item in e.Item.OwnerTableView.Items)
{
if(item.Expanded && item != e.Item)
{
item.Expanded = false;
}
}
}
}
http://www.telerik.com/help/aspnet-ajax/grdsingleexpandinhierarchicalgrid.html
(2)展开或者折叠所有行
protected void RadGrid1_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExpandCollapseCommandName)
{
(e.Item.FindControl("btnExpand") as ImageButton).Visible = !(e.Item.FindControl("btnExpand") as ImageButton).Visible;
(e.Item.FindControl("btnCollapse") as ImageButton).Visible = !(e.Item.FindControl("btnCollapse") as ImageButton).Visible;
}
if (e.CommandName == "ExpandAll")
{
//Looping through each DataItem and making the "btnExpand" image button in the item visibility to false and "btnCollapse" visibility to true
foreach (GridDataItem GridDataItem in RadGrid1.MasterTableView.GetItems(new GridItemType[] { GridItemType.Item, GridItemType.AlternatingItem }))
{
ImageButton btnExpand = (ImageButton)GridDataItem.FindControl("btnExpand");
btnExpand.Visible = false;
ImageButton btnCollapse = (ImageButton)GridDataItem.FindControl("btnCollapse");
btnCollapse.Visible = true;
}
//Exapanding the DataItem
foreach (GridDataItem item in RadGrid1.Items)
{
item.Expanded = true;
}
//Hiding the CollapseAll image in the header to true and ExpandAll image in the header to false
GridHeaderItem GridHeaderItem = e.Item as GridHeaderItem;
ImageButton imgCollapseAll = (ImageButton)GridHeaderItem.FindControl("CollapseAll");
imgCollapseAll.Visible = true;
ImageButton imgExpandAll = (ImageButton)GridHeaderItem.FindControl("ExpandAll");
imgExpandAll.Visible = false;
}
if (e.CommandName == "CollapseAll")
{
//Looping through each DataItem and making the "btnExpand" image button in the item visibility to true and "btnCollapse" visibility to false
foreach (GridDataItem GridDataItem in RadGrid1.MasterTableView.GetItems(new GridItemType[] { GridItemType.Item, GridItemType.AlternatingItem }))
{
ImageButton btnExpand = (ImageButton)GridDataItem.FindControl("btnExpand");
btnExpand.Visible = true;
ImageButton btnCollapse = (ImageButton)GridDataItem.FindControl("btnCollapse");
btnCollapse.Visible = false;
}
//Collapsing the DataItem
foreach (GridDataItem item in RadGrid1.Items)
{
item.Expanded = false;
}
//Hiding the CollapseAll image in the header to false and ExpandAll image in the header to true
GridHeaderItem GridHeaderItem = e.Item as GridHeaderItem;
ImageButton imgCollapseAll = (ImageButton)GridHeaderItem.FindControl("CollapseAll");
imgCollapseAll.Visible = false;
ImageButton imgExpandAll = (ImageButton)GridHeaderItem.FindControl("ExpandAll");
imgExpandAll.Visible = true;
}
}
(3)导致Grid重新绑定数据【Commands that invoke Rebind() implicitly】
Here is the complete list of commands that trigger Rebind():
Command Name
Field
ExpandCollapse
RadGrid.ExpandCollapseCommandName
Update
RadGrid.UpdateCommandName
Cancel
RadGrid.CancelCommandName
Delete
RadGrid.DeleteCommandName
Edit
RadGrid.EditCommandName
InitInsert
RadGrid.InitInsertCommandName
PerformInsert
RadGrid.PerformInsertCommandName
RebindGrid
RadGrid.RebindGridCommandName
Page
RadGrid.PageCommandName
Sort
RadGrid.SortCommandName
Filter
RadGrid.FilterCommandName
Note that the following commands do not perform internal rebind:
Select
RadGrid.SelectCommandName
Deselect
RadGrid.DeselectCommandName
http://www.telerik.com/help/aspnet-ajax/grdcommandsthatinvokerebindimplicitly.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY