欢迎光临
我们一直在努力

DataGrid代码(一)-.NET教程,数据库应用

建站超值云服务器,限时71元/月

 

using system;
using system.collections;
using system.data;
using system.web.ui.webcontrols;

namespace my.utils {
    /// <summary>
    /// datagrid工具集
    /// </summary>
    public class datagridutils {
        public datagridutils() {
        }

        /// <summary>
        /// 返回datagrid的模板列的checkbox
        /// </summary>
        /// <param name=”dglist”>datagrid</param>
        /// <returns>选中记录的值</returns>
        public static string[] getid (datagrid dglist) {
            return getid(dglist, “chkid”);
        }

        /// <summary>
        /// 返回datagrid的模板列的checkbox
        /// </summary>
        /// <param name=”dglist”>datagrid</param>
        /// <param name=”chkid”>checkbox的服务器端id</param>
        /// <returns>选中记录的值</returns>
        public static string[] getid (datagrid dglist, string chkid) {
            return getid(dglist, chkid, 0);
        }

        /// <summary>
        /// 返回datagrid的模板列的checkbox
        /// </summary>
        /// <param name=”dglist”>datagrid</param>
        /// <param name=”chkid”>checkbox的服务器端id</param>
        /// <param name=”index”>选中的值的索引列</param>
        /// <returns>选中记录的值</returns>
        public static string[] getid (datagrid dglist, string chkid, int index) {
            ilist list = new arraylist();
            foreach(datagriditem dgi in dglist.items) {
               
                //chkid是每个记录项的id,记住,这是服务器端的id,不是客户端的id.
                system.web.ui.control l_ct = dgi.cells[0].findcontrol(chkid);
                if(l_ct != null) {
                    //下面语句是判断是否记录项的checkbox框初选种
                    if(((system.web.ui.webcontrols.checkbox)l_ct).checked) {
                        list.add(dgi.cells[index].text);
                    }
                }
            }
            if (list.count == 0) {
                return null;
            } else {
                string[] s = new string[list.count];
                list.copyto(s, 0);
                return s;
            }
        }

        /// <summary>
        /// 设置datagrid的分页
        /// </summary>
        /// <param name=”dg”>datagrid</param>
        /// <param name=”dt”>datatable</param>
        public static void setpage (datagrid dg, datatable dt) {
            //最大页
            int maxpage = (int)(dt.rows.count + dg.pagesize – 1) / dg.pagesize;

            if (maxpage == 0) {
                maxpage = 1;
            }

            if (dg.currentpageindex >= maxpage){
                dg.currentpageindex = maxpage – 1;
            }
          
            //如果是datagridtable,设置全部记录数,polluxliu.common.datagridtable只是为了兼容crm之前的项目
            if (dg.gettype().fullname.equals(“polluxliu.common.datagridtable”)) {
                //((polluxliu.common.datagridtable)dg).maxrecord = dt.rows.count;
            } else if (dg.gettype().fullname.equals(“polluxliu.ui.webcontrols.datagridtable”)) {
                ((polluxliu.ui.webcontrols.datagridtable)dg).maxrecord = dt.rows.count;
            }

            dg.datasource = dt;
        }
    }
}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » DataGrid代码(一)-.NET教程,数据库应用
分享到: 更多 (0)