列表控件扩展方法绑定

    public static class ExtendMethods

    {

        /// <summary>

        /// 绑定列表控件

        /// </summary>

        /// <param name="listControl">列表控件</param>

        /// <param name="dt">数据表</param>

        public static void BindListControl(this ListControl listControl, DataTable dt)

        {

            if (dt != null)

            {

                listControl.DataSource = dt;

                listControl.DataTextField = dt.Columns[1].Caption;

                listControl.DataValueField = dt.Columns[0].Caption;

                listControl.DataBind();

            }

        }

    }

 

你可能感兴趣的:(方法)