检测 RadGrid 项目展开/折叠状态的变化

发布于 2024-10-27 03:17:53 字数 186 浏览 2 评论 0原文

我有一个显示层次结构的 RadGrid。我想保存网格中每个项目的展开/折叠状态,以便当用户返回站点时,所有内容看起来都与他们离开时完全相同。我有代码来保存和恢复展开/折叠项目的状态,但是,我现在需要一种方法来检测当用户单击展开/折叠图标时当前正在展开/折叠的项目。我知道有一个命令事件,但没有命令参数,也没有任何迹象表明哪个项目的状态正在改变。有什么想法吗?

I have a RadGrid displaying a hierarchical structure. I want to save the expand/collapse state of each item in the grid so that when the user returns to the site, everything looks exactly as they left it. I have code to save and restore the state of expanded/collapsed items, however, I now need a way to detect which item is currently being expanded/collapsed when the user clicks on the expand/collapse icon. I know there's a command event, but there is no command argument nor does there seem to be any indication of which item's state is being changed. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖凝香 2024-11-03 03:17:53

我发现传递到 RadGrid.ItemCommand 事件的 GridCommandEventArgs 包含一个“Item”属性,该属性表示展开/折叠的项目。如果转换为 GridDataItem,则可以检索数据键并执行任何必要的操作。

protected void RadGrid_OnItemCommand(object sender, GridCommandEventArgs e)
{
    try
    {
        if(e.CommandName.Equals("ExpandCollapse"))
        {
            string id = ((GridDataItem)e.Item).GetDataKeyValue("ID").ToString();
            // ... do work on id (i.e. save state, etc.) ...
        }
    } catch(Exception ex)
    {
        // What could possibly go wrong? :)
    }
}

I found that the GridCommandEventArgs passed into the RadGrid.ItemCommand event contains an 'Item' property that represents the item that was expanded/collapsed. If casted to a GridDataItem, one can retrieve the data key and do whatever manipulation is necessary.

protected void RadGrid_OnItemCommand(object sender, GridCommandEventArgs e)
{
    try
    {
        if(e.CommandName.Equals("ExpandCollapse"))
        {
            string id = ((GridDataItem)e.Item).GetDataKeyValue("ID").ToString();
            // ... do work on id (i.e. save state, etc.) ...
        }
    } catch(Exception ex)
    {
        // What could possibly go wrong? :)
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文