日期:2014-05-17  浏览次数:20978 次

ASP.NET TreeView控件回传问题

TreeView控件默认不回传TreeNodeCheckChanged事件

需要加入一个javascript函数:

 function postBackObject() {
            var o = window.event.srcElement;
            if (o.type == "checkbox") {
                __doPostBack("UpdatePanel1", "");
            }
        }

这里使用UpdatePanel控件实现无刷新回传效果

UpdatePanel1为UpdatePanel控件ID号


    private FunctionManager functionManager = new FunctionManager();
    private RoleFunctionManager roleFunctionManager = new RoleFunctionManager();
    //保存所有功能
    List<FunctionInfo> functions;
    //保存角色所具有的功能id
    List<int> functionIds;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["roleId"] == null)
        {
            Response.Redirect("RoleList.aspx");
        }

        if (!IsPostBack)
        {
            //获取所有功能
            functions = functionManager.GetAllFunction();

            int roleId = Convert.ToInt32(Request.QueryString["roleId"]);
           
            //获取角色具有的功能
            functionIds = roleFunctionManager.GetFunctionIdByRoleId(roleId);

            //遍历FId为0的节点,即根节点
            foreach (FunctionInfo function in functions.Where(p=>p.FId==0))
            {
                //创建一个TreeNode节点
                TreeNode tn = new TreeNode();
                //设置该节点显示的文本
                tn.Text = function.Content;
                //设置节点的值
                tn.Value = function.FunctionId.ToString();
                //判断当前节点是否是该角色具有的功能,如果是,则标记为选中状态
                if (functionIds.Count > 0 && functionIds.Where(p => p == function.FunctionId).Count() == 1)
                {
                    tn.Checked = true;
                }
             &