在论坛里发现了一个好用的类GridViewHelper,但是论坛提供的地址http://www.agrinei.com/gridviewhelper/gridviewhelpersample_en.zip 怎么都没有办法下载,请问谁有,能给我一个新的链接。或者发到  万分感谢!!!!
 

解决方案 »

  1.   


    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections;
    using BusinessLogic;public class GridViewHelper
    {
        public GridViewHelper()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }    /// <summary>
        /// 得到GridView中选中的主键值    /// </summary>
        /// <param name="gv">GridView对象</param>
        /// <returns>IEnumerable对象,里面是选中的记录的主键</returns>
        public static IEnumerable GetSelectedDataKeys(GridView gv)
        {
            return GetSelectedDataKeys(gv, "GridViewID");
        }    /// <summary>
        /// 得到GridView中选中的主键值    /// </summary>
        /// <param name="gv">GridView对象</param>
        /// <param name="checkboxID">GridView中CheckBox控件的ID</param>
        /// <returns>IEnumerable对象,里面是选中的记录的主键</returns>
        public static IEnumerable GetSelectedDataKeys(GridView gv, string checkboxID)
        {
            foreach (GridViewRow gvr in gv.Rows)
            {
                if (gvr.RowType == DataControlRowType.DataRow && gvr.FindControl(checkboxID) != null && ((CheckBox)gvr.FindControl(checkboxID)).Checked)
                {
                    yield return gv.DataKeys[gvr.RowIndex].Value.ToString();
                }
            }
        }    /// <summary>
        /// 得到GridView中选中的主键值    /// </summary>
        /// <param name="gv">GridView对象</param>
        /// <returns>选中的记录的主键值</returns>
        public static string GetSelectedDataKey(GridView gv)
        {
            return GetSelectedDataKey(gv, "GridViewID");
        }    /// <summary>
        /// 得到GridView中选中的主键值    /// </summary>
        /// <param name="gv">GridView对象</param>
        /// <param name="checkboxID">GridView中CheckBox控件的ID</param>
        /// <returns>选中的记录的主键值</returns>
        public static string GetSelectedDataKey(GridView gv, string checkboxID)
        {
            foreach (GridViewRow gvr in gv.Rows)
            {
                if (gvr.RowType == DataControlRowType.DataRow && gvr.FindControl(checkboxID) != null && ((CheckBox)gvr.FindControl(checkboxID)).Checked)
                {
                    return gv.DataKeys[gvr.RowIndex].Value.ToString();
                }
            }
            return "";
        }    /// <summary>
        /// 添加鼠标移动变换底色效果,并增加鼠标双击某行跳转到指定url功能
        /// </summary>
        /// <param name="gv">要进行处理的GridView</param>
        /// <param name="mouseDoubleClickForwardUrl">鼠标双击某行跳转到指定url</param>
        public static void SetMouseOverColorAndDbClickUrl(GridView gv, string mouseDoubleClickForwardUrl)
        {
            //设定Gridview控件中每行数据的脚本效果
            string MouseOverBgColor = ConfigurationManager.AppSettings[SystemConst.CONFIG_GRIDVIEW_MOUSEOVERBGCOLOR];
            foreach (GridViewRow row in gv.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    //添加自定义属性,当鼠标移过来时设置该行的背景色,并保存原背景色                //鼠标划过时改变光标 Modify by 陈根发 20070802
                    row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='" + MouseOverBgColor + "';this.style.cursor = 'hand'");
                    //添加自定义属性,当鼠标移走时还原该行的背景色
                    row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;this.style.cursor = 'default'");                if (mouseDoubleClickForwardUrl != null && mouseDoubleClickForwardUrl.Trim().Length > 0)
                    {
                        //添加自定义属性,当鼠标双击该行时,跳转到该行数据的编辑页面  
                        row.Attributes.Add("ondblclick", "location='" + mouseDoubleClickForwardUrl + gv.DataKeys[row.RowIndex].Value.ToString() + "'");
                    }
                }
            }
        }    /// <summary>
        ///     /// 添加鼠标移动变换底色效果,并增加鼠标双击某行弹出新的指定url页面功能
        /// </summary>
        /// <param name="gv">要进行处理的GridView</param>
        /// <param name="mouseDoubleClickForwardUrl">鼠标双击某行跳转到指定url</param>
        public static void SetMouseOverColorAndDbClickUrl(GridView gv, string mouseDoubleClickForwardUrl, int left, int top, int width, int height)
        {
            //设定Gridview控件中每行数据的脚本效果
            string MouseOverBgColor = ConfigurationManager.AppSettings[SystemConst.CONFIG_GRIDVIEW_MOUSEOVERBGCOLOR];
            foreach (GridViewRow row in gv.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    //添加自定义属性,当鼠标移过来时设置该行的背景色,并保存原背景色
                    //鼠标划过时改变光标 Modify by 陈根发 20070802
                    row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='" + MouseOverBgColor + "';this.style.cursor = 'hand'");
                    //添加自定义属性,当鼠标移走时还原该行的背景色
                    row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;this.style.cursor = 'default'");                if (mouseDoubleClickForwardUrl != null && mouseDoubleClickForwardUrl.Trim().Length > 0)
                    {
                        //添加自定义属性,当鼠标双击该行时,跳转到该行数据的编辑页面  
                        string url = string.Format("window.open('{0}','','left={1},top={2},height={3},width={4},menubar=no,toolbar=no,location=no,status=no,scrollbars=no,resizable=no');", mouseDoubleClickForwardUrl + gv.DataKeys[row.RowIndex].Value.ToString(), left, top, width, height);
                        row.Attributes.Add("ondblclick", url);
                    }
                }
            }
        }
        
       }