要求:根据ID来控制ImageButton的显示和隐藏(所有数据加载时进行控制)
.aspx页面
<dxwtl:ASPxTreeList ID="treeListSysModule"runat="server" KeyFieldName="ID"
ParentFieldName="PID" Width="660px"
ClientInstanceName="treeListSysModule"
OnCustomCallback="treeListSysModule_CustomCallback"
OnHtmlDataCellPrepared="treeListSysModule_HtmlDataCellPrepared">
<StylesCell-HorizontalAlign="Left">
<CellHorizontalAlign="Left"></Cell>
</Styles>
<SettingsPager PageSize="20" Mode="ShowPager"></SettingsPager>
<Settings GridLines="Both" />
<Columns>
<dxwtl:TreeListTextColumn Caption="ID"FieldName="ID" VisibleIndex="0"Visible="false"></dxwtl:TreeListTextColumn>
<dxwtl:TreeListTextColumn Caption="系统名称"FieldName="sysname" VisibleIndex="1"></dxwtl:TreeListTextColumn>
<dxwtl:TreeListTextColumn Caption="修改"VisibleIndex="2" >
<DataCellTemplate>
<center>
<asp:ImageButton ID ="imgbtnUpdateWeb" runat="server" ImageUrl="~/Images/img/updateico.gif" AlternateText="修改"CommandArgument ='<%# eval_r("ID")%>' CommandName="update"OnCommand="imgbtnUpdateWeb_Command"/>
</center>
</DataCellTemplate>
</dxwtl:TreeListTextColumn>
<dxwtl:TreeListTextColumn Caption="角色"VisibleIndex="3" >
<DataCellTemplate>
<center>
<asp:ImageButton ID="imgbtnRole"runat="server" AlternateText="角色" ImageUrl="~/Images/img/perm.gif"CommandArgument='<%# eval_r("ID")%>' CommandName="Role"OnCommand="imgbtnRole_Command" />
</center>
</DataCellTemplate>
</dxwtl:TreeListTextColumn>
<dxwtl:TreeListTextColumn Caption="删除"VisibleIndex="4" >
<DataCellTemplate >
<center>
<asp:ImageButton ID="imgbtnDelete"runat="server" ImageUrl="~/Images/img/delete.gif"OnClientClick="return confirm('你确定要删除此记录吗?');" AlternateText="删除"CommandArgument='<%# eval_r("ID") %>'CommandName="De"OnCommand="imgbtnDelete_Command"/>
</center>
</DataCellTemplate>
</dxwtl:TreeListTextColumn>
</Columns>
</dxwtl:ASPxTreeList>
.cs文件
using DevExpress.Web.ASPxTreeList;
///<summary>
///控制修改、角色、删除按钮
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
protectedvoid treeListSysModule_HtmlDataCellPrepared(object sender,DevExpress.Web.ASPxTreeList.TreeListHtmlDataCellEventArgs e)
{
if (e.NodeKey.Substring(e.NodeKey.Length - 3, 3) == "000")
{
ImageButton imgUpdate =treeListSysModule.FindDataCellTemplateControl(e.NodeKey,treeListSysModule.Columns[2] as TreeListDataColumn,"imgbtnUpdateWeb") as ImageButton;
ImageButton imgRole =treeListSysModule.FindDataCellTemplateControl(e.NodeKey,treeListSysModule.Columns[3] as TreeListDataColumn, "imgbtnRole")as ImageButton;
ImageButton imgDelete =treeListSysModule.FindDataCellTemplateControl(e.NodeKey,treeListSysModule.Columns[4] as TreeListDataColumn, "imgbtnDelete")as ImageButton;
imgUpdate.Visible = false;
imgRole.Visible = false;
imgDelete.Visible = false;
}
else
{
ImageButton imgUpdate =treeListSysModule.FindDataCellTemplateControl(e.NodeKey,treeListSysModule.Columns[2] as TreeListDataColumn,"imgbtnUpdateWeb") as ImageButton;
ImageButton imgRole =treeListSysModule.FindDataCellTemplateControl(e.NodeKey,treeListSysModule.Columns[3] as TreeListDataColumn, "imgbtnRole")as ImageButton;
ImageButton imgDelete =treeListSysModule.FindDataCellTemplateControl(e.NodeKey,treeListSysModule.Columns[4] as TreeListDataColumn, "imgbtnDelete")as ImageButton;
imgRole.Visible = true;
imgDelete.Visible = true;
imgUpdate.Visible = true;
}
注:e.NodeKey就是页面绑定的主键ID。