protected void gvTest_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //如果是绑定数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //鼠标经过时,行背景色变
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
                //鼠标移出时,行背景色变
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
                //为gridview行添加双击事件
                string url = "http://www.baidu.com";
                e.Row.Attributes.Add("ondblclick", "javascript:parent.location.href='"+url+"'");
                //为gridview列添加click事件
                e.Row.Cells[3].Attributes.Add("onclick", "javascript:parent.location.href='" + url + "'");
            }
            //如果是绑定数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {
                    //删除前弹出确认框
                    ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[2].Text + "\"吗?')");
                }
            }
            if (e.Row.RowIndex != -1)//自动生成编码列
            {
                int id = e.Row.RowIndex + 1;
                e.Row.Cells[0].Text = id.ToString();
            }
            if (e.Row.RowIndex != -1)//过长的内容,用...代替
            {
                string strInfo = e.Row.Cells[2].Text;
                e.Row.Cells[2].Text = SubStr(strInfo, 1);
                e.Row.Cells[2].ToolTip = strInfo;
            }
            if (e.Row.RowIndex == 5)//突出显示某信息
            {
                e.Row.Cells[0].BackColor = System.Drawing.Color.Red;
            }
        }
        public string SubStr(string sString, int nLeng)
        {
            if (sString.Length <= nLeng)
            {
                return sString;
            }
            string sNewStr = sString.Substring(0, nLeng);
            sNewStr = sNewStr + "...";
            return sNewStr;
        }

Gridview的RowDataBound事件可以做很多事情的更多相关文章

  1. JS可以做很多事情

    JS可以做很多事情,例如: 使用JavaScript可以做很多事情,使网页更具互动性,并为网站用户提供更好.更令人兴奋的体验.JavaScript允许您创建一个活动的用户界面,当用户在页面之间导航时, ...

  2. Gridview的RowDataBound事件(添加删除提示,改变背景颜色)

    protected void gvTest_RowDataBound(object sender, GridViewRowEventArgs e) { //如果是绑定数据行 if (e.Row.Row ...

  3. GridView的RowDataBound事件中获取当前行内容的几种方法

    1. Cells[x].Txt.    从列单元格的文本值获取.这种方法简单高率,最为常用,但是功能单纯.此法存在几个缺点:   (1)无法获取到设置了隐藏属性的数据列的值,所取到的值为“”(空).  ...

  4. GridView通过RowDataBound事件获取字段值、数据源列值

    如果数据源有某一列,而在绑定到GridView时不显示该列,编程时要用到该列的值可以用以下方法: protected void GridView1_RowDataBound(object sender ...

  5. 在GridView的RowDataBound事件中获取某行某列的值!

    protected void gdvOrders_RowDataBound(object sender, GridViewRowEventArgs e)   {               if (e ...

  6. GridView的 PreRender事件与 RowCreated、RowDataBound事件大乱斗

    GridView的 PreRender事件与 RowCreated.RowDataBound事件大乱斗 之前写了几个范例,做了GridView的 PreRender事件与 RowCreated.Row ...

  7. GridView的 PreRender事件与范例--GridView + CheckBox,点选多列资料(复选删除)

    GridView的 PreRender事件与范例--GridView + CheckBox,点选多列资料(复选删除) 之前有一个范例,相同的结果可以用两种作法来实践 [GridView] 资料系结表达 ...

  8. [C# 基础知识系列]专题五:当点击按钮时触发Click事件背后发生的事情 (转载)

    当我们在点击窗口中的Button控件VS会帮我们自动生成一些代码,我们只需要在Click方法中写一些自己的代码就可以实现触发Click事件后我们Click方法中代码就会执行,然而我一直有一个疑问的—— ...

  9. GridView控件RowDataBound事件中获取列字段值的几种途径 !!!

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == ...

随机推荐

  1. ArcGIS案例学习笔记4_2

    ArcGIS案例学习笔记4_2 联系方式:谢老师,135_4855_4328,xiexiaokui#qq.com 时间:第4天下午 案例1:批量水文分析地理建模 数据:实验数据\Chp11\tutor ...

  2. 给定一个十进制数,将其转化为N进制数-----17年滴滴笔试题

    题目:给定一个十进制数M,将其转化为N进制数,其中2<=N<=16,其中N为32为整型数; 输入:M N,如7 2 输出转化结果:111 注意点:考虑负数的情况,记得添加负号(其实直接添加 ...

  3. 实现Action的三种方式

    实现Action的三种方式: 1.普通类  一般采用此种方法 2.实现Action接口 3.继承ActionSupport类

  4. 自然对数e(转)

    e表示增长的极限 e=limx→+∞ (1+1/x)^x≍2.71828 假设,一根竹子,第一天是1米,第二天长了1米,然后这根柱子的长度变成了2米.相当于 (1+1/1)^1.上面这个假设,如果仔细 ...

  5. Python3 ssl模块不可用的问题

    编译安装完Python3之后,使用pip来安装python库,发现了如下报错: $ pip install numpy pip is configured with locations that re ...

  6. 大型运输行业实战_day10_1_自定义事务管理类

    1.创建事务管理类  TransactionManager.java package com.day02.sation.transaction; import com.day02.sation.uti ...

  7. mysql与redis的区别与联系

    1.mysql是关系型数据库,主要用于存放持久化数据,将数据存储在硬盘中,读取速度较慢. redis是NOSQL,即非关系型数据库,也是缓存数据库,即将数据存储在缓存中,缓存的读取速度快,能够大大的提 ...

  8. The Unique MST

    The Unique MST http://poj.org/problem?id=1679 Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  9. [leetcode]416. Partition Equal Subset Sum分割数组的和相同子集

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  10. Spring框架之演示JDBC的模板类

    1. 步骤一:创建数据库的表结构 create database spring_day03; use spring_day03; create table t_account( id int prim ...