(1)根据内容设置GridView某些行,或单元格的颜色。

Code
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[8].Text == "USA")
            {
                e.Row.BackColor = System.Drawing.Color.Red;
                //e.Row.Cells[8].BackColor = System.Drawing.Color.Red;
            }
        }
    }

(2)GridView复选框实现全部选择。

Code
   protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        int i;
        if (((CheckBox)sender).Checked)
        {
            for (i = 0; i < GridView1.Rows.Count; i++)
            {
                ((CheckBox)GridView1.Rows[i].FindControl("CheckBox1")).Checked = true;
            }
        }
        else
        {
            for (i = 0; i < GridView1.Rows.Count; i++)
            {
                ((CheckBox)GridView1.Rows[i].FindControl("CheckBox1")).Checked =false;
            }
        }
    }

(3)GridView导出表到excel文件。

提供了对分页的支持,如果需要屏敝某些列,将这些列的Visible属性设为false即可。需要注意的是,一定要对方法VerifyRenderingInServerForm(Control control)进行重载。

Code
   protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.Charset = "GB2312";
        Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
        // 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

bool bPage = GridView1.AllowPaging;
        if (bPage)
        {
            GridView1.AllowPaging = false;
            GridView1.DataBind();
        }

this.GridView1.RenderControl(oHtmlTextWriter);
        Response.Output.Write(oStringWriter.ToString());
        Response.Flush();
        Response.End();

if (bPage)
        {
            GridView1.AllowPaging = true;
            GridView1.DataBind();
        }

}
    public override void VerifyRenderingInServerForm(Control control)
    { 
    }

(4)鼠标移到GridView某行时,动态改变该行的背景颜色。

Code
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow )
        {
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#C0C0FF';this.style.cursor='hand';");
            //当鼠标移走时还原该行的背景色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
        }
    }

(5)GridView响应单击或双击行事件。

Code
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if(e.Row.RowType==DataControlRowType.DataRow)
        {
            //e.Row.Attributes.Add("ondblclick", "ReKey('" + e.Row.Cells[2].Text+"')");
            //e.Row.Attributes.Add("onclick", "alert('" + e.Row.Cells[2].Text + "')");
            e.Row.Attributes.Add("ondblclick", "window.open('http://www.sina.com?name=" + e.Row.Cells[2].Text + "')");
            e.Row.Attributes["style"] = "Cursor:hand"; 
            // //键盘事件
            //e.Row.Attributes.Add("OnKeyDown", "GridViewItemKeyDownEvent('" + e.Row.Cells[1].Text + "')");

}

}

(6)GridView添加删除确认。

将原有的删除列转化为模板列,在页面上添加确认代码:

OnClientClick='return confirm("确认要删除吗?")'

玩转GridView相关推荐

  1. 玩转控件:对Dev的GridControl控件扩展

    缘由 一切实现来源于需求,目的在于不盲目造轮子,有小伙伴儿在看了<玩转控件:对Dev中GridControl控件的封装和扩展>文章后,私信作者说,因公司业务逻辑比较复杂,展示字段比较多,尤 ...

  2. FishRedux完成一个玩安卓客户端

    文章目录 FishRedux完成一个玩安卓客户端 前言 基本架子 页面预览 路由定义: 首页 view and so on 定义自己的TabController 页面保活 Adapter写法 adap ...

  3. 基于Android应用《玩转英语》(总报告)

                                                                         基于Android应用<玩转英语>   摘  要 ...

  4. 13.ListView和GridView

    转载请标明出处:  http://blog.csdn.net/yujun411522/article/details/46226001 本文出自:[yujun411522的博客] android组件中 ...

  5. 玩转Qml(3)-换皮肤

    简介 效果预览 必要的基础 QObject自定义属性 全局单例 实现 皮肤的配置和原理 皮肤选择器 带三角形尖尖的弹窗组件 简介 本文是<玩转Qml>系列文章的第三篇,涛哥将教大家,如何在 ...

  6. GridView网格组件,实现疯狂猜图的首页选关功能

    通过GridView实现网格显示组件的功能. 使用方法类似ListView,也需要通过Adapter加入数据 首先,建立主页的布局activity_stage_select.xml <Linea ...

  7. Android基础GridView、ListView、Edittext属性大全

    前言:Android基础控件的属性,在开发过程中会用到,另外多了解一些属性会加快功能的实现,特别是Edittext文本输入在用户填写时肯定用到,如果充分利用其属性,会事半功倍.有很多控件特殊属性连an ...

  8. 【玩转SQLite系列】(六)SQLite数据库应用案例实现历史搜索记录

    转载请注明出处:http://blog.csdn.net/linglongxin24/article/details/53366564 本文出自[DylanAndroid的博客] [玩转SQLite系 ...

  9. 初试linux编译(ubuntu+vim)+玩转智能蛇

    一.初试linux编译(ubuntu+vim) 步骤: ①下载vmware15+ubuntu桌面版映像 ②安装ubuntu ③下载vim+gcc 在ubuntu终端输入: sudo apt-get i ...

最新文章

  1. 【CV】Pytorch一小时入门教程-代码详解
  2. 格灵深瞳算法团队获得NIST人脸识别竞赛全球第一
  3. HTTP长连接和短连接 + Websocket
  4. Microsoft重申对F#的支持
  5. 人体肺活量测试软件,人体肺活量怎么测试
  6. weka: exhaustive search
  7. 从一个页面跳转到用swiper写的全屏滚动页面的指定位置
  8. [转载] 使用backbone.js、zepto.js和trigger.io开发HTML5 App
  9. 中班游戏电子计算机,幼儿园中班数学游戏:小小快递员
  10. linux一切皆是文件_Linux 的虚拟文件系统(真正理解“一切皆文件”)
  11. 数据库与hadoop_OLTP,MPP和Hadoop
  12. shell的EOF用法
  13. Javascript异步操作(Promise)
  14. H5打包成app的在线工具
  15. 同时删除多个 Word 文档空白行
  16. 【观察】嵌入式AI崛起,这里有一本通关“秘籍”
  17. 求实数的整数部分和小数部分python_python求实数的整数部分
  18. java满天星星闪烁_夜空当中满天的星星为什么会闪烁?
  19. 网易2018实习生招聘笔试题
  20. 浅谈 css的zoom属性

热门文章

  1. 专访趋势科技CEO陈怡桦:病毒行业需要反省
  2. Angular 2 Pipe
  3. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem D. Grumpy Cat 交互题
  4. EDM数据营销概念简要介绍
  5. 前端人员如何模拟慢网速环境
  6. react 禁止微信调整字体大小
  7. 中断的顶半部和底半部
  8. webpack源码阅读——npm脚本运行webpack与命令行输入webpack的区别
  9. 当RxJava遇到AOP
  10. tableview 展开