绑定dropdownlist

    技术2022-05-11  14

    using System;using System.Collections.Generic;using System.Text;using ComponentArt.Web.UI;using System.Data;using System.Web.UI.WebControls;

    namespace eOffice.WebControls{    public static class UISet    {        /// <summary>        /// 设置Tab外观属性        /// </summary>        /// <param name="tab">Tab控件</param>        //public static void SetTabUI(TabStrip tab)        //{        //    tab.CssClass = "TabTopGroup";        //    tab.DefaultItemLookId = "DefaultTabLook";        //    tab.DefaultSelectedItemLookId = "SelectedTabLook";        //    tab.DefaultGroupTabSpacing = 2;        //    tab.ImagesBaseUrl = "/images/TabStripImages/";                    //    ItemLook defaultIL = new ItemLook();        //    defaultIL.CssClass = "DefaultTab";        //    defaultIL.LookId = "DefaultTabLook";        //    defaultIL.HoverCssClass="DefaultTabHover";         //    defaultIL.LeftIconUrl="tab_left_icon.gif";         //    defaultIL.RightIconUrl="tab_right_icon.gif";                             //    defaultIL.LabelPaddingLeft=1;         //    defaultIL.LabelPaddingRight=15;         //    defaultIL.LabelPaddingTop=5;         //    defaultIL.LabelPaddingBottom=4;         //    defaultIL.LeftIconWidth=4;        //    defaultIL.LeftIconHeight=30;

            //    ItemLook selectedIL = new ItemLook();        //    selectedIL.CssClass = "SelectedTab";        //    selectedIL.LookId = "SelectedTabLook";        //    selectedIL.HoverCssClass = "DefaultTabHover";        //    selectedIL.LeftIconUrl = "selected_tab_left_icon.gif";        //    selectedIL.RightIconUrl = "selected_tab_right_icon.gif";        //    selectedIL.LabelPaddingLeft = 1;        //    selectedIL.LabelPaddingRight = 15;        //    selectedIL.LabelPaddingTop = 5;        //    selectedIL.LabelPaddingBottom = 4;        //    selectedIL.LeftIconWidth = 4;        //    selectedIL.LeftIconHeight = 30;

            //    tab.ItemLooks.Add(defaultIL);        //    tab.ItemLooks.Add(selectedIL);        //}

            /// <summary>        /// 绑定数据源至控件        /// </summary>        /// <param name="ds">数据源</param>        /// <param name="ddl">控件</param>        /// <param name="FieldName">显示的字段</param>        /// <param name="FieldValue">值字段</param>        /// <param name="Blankable">是否添加空选项</param>        public static void BindDDL(DataSet ds, DropDownList ddl, string FieldName, string FieldValue, bool Blankable)        {            if (Blankable)                ddl.Items.Add(new ListItem("", ""));            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)            {                ddl.Items.Add(new ListItem(ds.Tables[0].Rows[i][FieldName].ToString(), ds.Tables[0].Rows[i][FieldValue].ToString()));            }        }

            /// <summary>        /// 绑定系统选项配置        /// </summary>        /// <param name="ds">数据源</param>        /// <param name="ddl">被绑定控件</param>        public static void BindConfigDDL(DataSet ds, DropDownList ddl, bool Blankable)        {            BindDDL(ds, ddl, "DataName", "ConfigDataID", Blankable);        }

            /// <summary>        /// 绑定系统选项配置        /// </summary>        /// <param name="ds">数据源</param>        /// <param name="ddl">被绑定控件</param>        public static void BindConfigDDL(DataSet ds, DropDownList ddl)        {            BindConfigDDL(ds, ddl, false);        }

            /// <summary>        /// 绑定选项配置        /// </summary>        /// <param name="ddl">被绑定控件</param>        public static void BindDDL( DropDownList ddl)        {            BindDDL(ddl, false);        }

            /// <summary>        /// 绑定选项配置-是/否        /// </summary>        /// <param name="ddl">被绑定控件</param>        public static void BindDDL(DropDownList ddl, bool Blankable)        {            if (Blankable)                ddl.Items.Add(new ListItem("", "-1"));            ddl.Items.Add(new ListItem("是", "True"));            ddl.Items.Add(new ListItem("否", "False"));        }

            /// <summary>        /// 绑定选项配置-男/女        /// </summary>        /// <param name="ddl">被绑定控件</param>        public static void BindDDLSex(DropDownList ddl, bool Blankable)        {            if (Blankable)                ddl.Items.Add(new ListItem("", "-1"));            ddl.Items.Add(new ListItem("男", "0"));            ddl.Items.Add(new ListItem("女", "1"));        }    }}

    例子:

     /// <summary>        /// 绑定dropdownlist        /// </summary>        public void bind_ddl()        {            UISet.BindDDL(new CfgDefect().GetAll(), ddlDefectCodeEN, "DEFECT_CODE_EN", "DEFECT_ID", true);            UISet.BindDDL(new CfgGroupDesc().GetAll(), ddlGropName, "GROUP_NAME", "GROUP_ID", true);        } 


    最新回复(0)