DropdownList用户使用缓存的解决方案

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using AppUtility;
using System.Web.Caching;
using System.Collections.Generic;
using Model;


namespace NewITOWeb.SystemUserControl
{
    public partial class SystemUserListUserControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //由于是用户控件,每次页面引用后,进入页面的PageLoad之后,会进入此用户控件的PageLoad,去掉IsPostBack
            //保证每次回发都能访问到数据,否则在引用页面会出现空下拉列表的形式。
            BindView();

        }

        private void BindView() 
        {

            int count = this.drpSysUserList.Items.Count;
            if(count==0)
            {
                if (Cache.Get("UserList") == null)
                {
                    UserRoleMappingService us = new UserRoleMappingService();
                    CacheHelper.CacheSaveTime = 30;
                    CacheHelper.InsertCacheAbsolute("UserList", us.GetSysUserList());

                }
                ListItem listItem = new ListItem("-请选择-", "0");
                this.drpSysUserList.Items.Add(listItem);
                List<UserRoleMapping> list = (List<UserRoleMapping>)Cache["UserList"];
                foreach (UserRoleMapping um in list)
                {
                    listItem = new ListItem(um.Name, um.SysUserID);
                    this.drpSysUserList.Items.Add(listItem);
                }
                this.drpSysUserList.DataBind();
                count = this.drpSysUserList.Items.Count;
            }
           
        }

        public string SysUserProperties
        {
            set
            {
                this.drpSysUserList.SelectedValue = value;
            }
            get
            {
                return this.drpSysUserList.SelectedValue;
            }
        }
    }
}

你可能感兴趣的:(DropdownList用户使用缓存的解决方案)