[英]Finding a Devexpress aspxribbon control by name
I have a very simple devexpress aspxribbon with controls to filter data by date which is built through databinding. 我有一个非常简单的devexpress aspxribbon,它具有通过数据绑定构建的按日期过滤数据的控件。 I'm trying to create a function on the server side which will take my ribbon object and go through its children and find a control with the given name. 我正在尝试在服务器端创建一个函数,该函数将接收我的功能区对象并遍历其子对象,并找到具有给定名称的控件。 The reason I have to use this is because you cannot set the ID or ClientInstanceName properties, which I would normally use, for the aspxribbon through databinding ( here's the list of allowed properties ). 我必须使用它的原因是因为您无法通过数据绑定( 这是允许的属性的列表 )为aspxribbon设置我通常使用的ID或ClientInstanceName属性。
My attempt at writing this function was basically just wishful thinking that the implicit conversion from a System Control to a Devexpress RibbonEditItem (so I could access the Name property) would work, which it obviously didn't. 我编写此函数的尝试基本上只是一厢情愿的想法,即从系统控件到Devexpress RibbonEditItem的隐式转换(这样我就可以访问Name属性)将起作用,但显然不起作用。 Any help would be appreciated! 任何帮助,将不胜感激!
Here's my XML that serves as the datasource for the ribbon: 这是我的XML,用作功能区的数据源:
<?xml version="1.0" encoding="utf-8" ?>
<TestInterface>
<Panel Name="FilterTab" Text="Filter">
<Group Name="DateSelectors" Text="Date Filter">
<Item Name="DateFrom" ClientInstanceName="DateFrom" ItemType="DateEdit"></Item>
<Item Name="DateTo" ItemType="DateEdit"></Item>
<Item Name="FilterSubmit" Text="Filter"></Item>
</Group>
<Group Name="PredefinedDateFilters" Text="Pre-Defined Filters">
<Item Name="FilterYesterday" Text="Yesterday"></Item>
<Item Name="Filter7" Text="7 Days"></Item>
<Item Name="Filter30" Text="30 Days"></Item>
</Group>
</Panel>
</TestInterface>
And here's the function I attempted to build: 这是我尝试构建的功能:
protected RibbonEditItemBase getbyName(string name, Control parent)
{
ControlCollection childControls = parent.Controls;
foreach(RibbonEditItemBase ctrl in childControls)
{
//found, return control
if (ctrl.Name == name)
return ctrl;
//recur for child controls
if (parent.Controls[ctrl.Index].Controls != null)
{
RibbonEditItemBase recur = getbyName(name, parent.Controls[ctrl.Index]);
//found, return control
if (recur != null)
return recur;
}
}
return null; //not found, return null
}
RibbonEditItemBase
class is not inherited from Control
class, so it cannot be converted to Control
. RibbonEditItemBase
类不是从Control
类继承的,因此无法将其转换为Control
。 To find particular item by name you can use Ribbon
->
Tab
->
Group
->
Item
hierarchy. 要按名称查找特定项目,可以使用Ribbon
->
Tab
->
Group
->
Item
层次结构。
Here is example: 这是示例:
protected RibbonEditItemBase getbyName(string name, ASPxRibbon ribbon)
{
foreach (RibbonTab tab in ribbon.Tabs)
foreach (RibbonGroup group in tab.Groups)
foreach (RibbonItemBase item in group.Items)
{
var edit = item as RibbonEditItemBase;
if (edit != null && edit.Name == name)
return edit;
}
return null; //not found, return null
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.