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. PCA和SVD(转)

    最近突然看到一个问题,PCA和SVD有什么关系?隐约记得自己照猫画虎实现的时候PCA的时候明明用到了SVD啊,但SVD(奇异值分解)和PCA的(特征值分解)貌似差得相当远,由此钻下去搜集了一些资料,把 ...

  2. ValueError: update only works with $ operators

    问题:在执行pymongo的update语句时,提示了ValueError: update only works with $ operators 脚本:db.user.update_one({&qu ...

  3. subprocess 粘包问题

    1.执行命令: 在py代码中去如何调用操作系统的命令 新模块:subprocess r = subprocess.Popen('ls',shell=True,stdout=subprocess.PIP ...

  4. jsoncpp在Windows和Linux下的安装

    Windows下: 参考这个网站,没什么问题,注意MTd这些选对就行了. http://www.cppblog.com/wanghaiguang/archive/2013/12/26/205020.h ...

  5. 在windows系统下安装oracle 11g

     oracle 11g 安装在windows server 2012 系统下. 最近,需要配置数据库,要求在windows操作系统下,安装oracle 11g 数据库,因为以前没有安装过,所以成功后, ...

  6. TPshop学习

    笔记大纲: tpshop目录结构 功能模块 函数库 重要配置 助手函数 插件 模板 1.TPshop目录结构 目录结构(来自官方视频截图) 看这个图,目录结构一目了然.下面要讲的内容也是根据这个图展开 ...

  7. 构建openssl debug版

    一.简介 作为一种安全协议,openssl囊括了主要的密码算法.常用的密钥和证书封装管理功能以及SSL协议,并提供了丰富的应用程序供测试或其它目的使用. 参考: http://www.linuxidc ...

  8. 测试用例excel模板

    Index Precondition Action Test Data Expect Result Excute Date Pass/Fail

  9. asp.net core 视图组件化

    视图组件可以通过partial view或viewcomponent实现 partialview https://docs.microsoft.com/zh-cn/aspnet/core/mvc/vi ...

  10. msys2 启用windows PATH环境变量

    有三种方法修改 ①msys2_shell.cmd 中取消一行的注释:set MSYS2_PATH_TYPE=inherit ②调用msys2_shell.cmd时使用-use-full-path参数 ...