DropListDown控件的数据绑定例子

来源:互联网 发布:申请网络空间 编辑:程序博客网 时间:2024/05/16 13:47
先在页面中将droplistdown控件AutoPostBack=true,然后开始绑定数据
 

1、Controller中执行绑定
ddlTransactor.DataBind(UIHelper.GetDepartName());   

2、UIHelper中整理需要的数据
public static DDLBindInfo GetDepartName()
        {
            DDLBindInfo info = new DDLBindInfo()
            {
                TextField = "DepartName",
                ValueField = "DepartID",
                DataSource = BaseDataHelper.GetDepartName(),
                TopItemText = "请选择所办理部门"
            };
            return info;
        }

3、BaseDataHelper中通过bll层取得详细的数据
internal static DataSet GetDepartName()
        {
            BLL.DepartName bll = new BLL.DepartName();
            string where = "LevelID='4'";
            return bll.GetList(where);
        }

4、bll层控制dat层与数据库交互
/// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
5、dat层从数据库中提取数据
/// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select DepartID,......) ");
            strSql.Append(" FROM DepartName,DeaprtNickName,LevelID ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
0 0
原创粉丝点击