您的位置:首页 > 编程语言 > ASP

为ASPxComboBox 控件动静态绑定下拉项的方法

2009-03-18 17:54 651 查看
1定义提供数据源的方法:protected IEnumerable GetParentRoleDataSource(object categoryId)
{
IEnumerable results = from r2 in eDataContext.Role
where r2.IsDeleted == false
select new { ParentRoleID = r2.RoleID, ParentRoleName = r2.RoleName };

return results;
}

2. 页面绑定数据源和键值,并且用value关联好

<dxe:ASPxComboBox ID="parentRoleComb" runat="server" Value='<%# Eval("ParentRoleID")%>' ValueField="ParentRoleID" TextField="ParentRoleName"

DataSource='<%# GetParentRoleDataSource(Eval("ParentRoleID")) %>' ValueType="System.Int32">

</dxe:ASPxComboBox>

3.在ASPxGridView1_HtmlEditFormCreated事件中为下拉框绑定顶级角色的值: ASPxComboBox currentBox = ((ASPxGridView)sender).FindEditFormTemplateControl("parentRoleComb") as ASPxComboBox;

//给DropDownList手动添加显示值(包括对应的后台值)
ListEditItem item = new ListEditItem("没有父角色", "0");

currentBox.Items.Insert(0, item); //把值添加到指定的索引位置
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐