Gridview的RowDataBound事件可以做很多事情
{
//如果是绑定数据行
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事件可以做很多事情的更多相关文章
- JS可以做很多事情
JS可以做很多事情,例如: 使用JavaScript可以做很多事情,使网页更具互动性,并为网站用户提供更好.更令人兴奋的体验.JavaScript允许您创建一个活动的用户界面,当用户在页面之间导航时, ...
- Gridview的RowDataBound事件(添加删除提示,改变背景颜色)
protected void gvTest_RowDataBound(object sender, GridViewRowEventArgs e) { //如果是绑定数据行 if (e.Row.Row ...
- GridView的RowDataBound事件中获取当前行内容的几种方法
1. Cells[x].Txt. 从列单元格的文本值获取.这种方法简单高率,最为常用,但是功能单纯.此法存在几个缺点: (1)无法获取到设置了隐藏属性的数据列的值,所取到的值为“”(空). ...
- GridView通过RowDataBound事件获取字段值、数据源列值
如果数据源有某一列,而在绑定到GridView时不显示该列,编程时要用到该列的值可以用以下方法: protected void GridView1_RowDataBound(object sender ...
- 在GridView的RowDataBound事件中获取某行某列的值!
protected void gdvOrders_RowDataBound(object sender, GridViewRowEventArgs e) { if (e ...
- GridView的 PreRender事件与 RowCreated、RowDataBound事件大乱斗
GridView的 PreRender事件与 RowCreated.RowDataBound事件大乱斗 之前写了几个范例,做了GridView的 PreRender事件与 RowCreated.Row ...
- GridView的 PreRender事件与范例--GridView + CheckBox,点选多列资料(复选删除)
GridView的 PreRender事件与范例--GridView + CheckBox,点选多列资料(复选删除) 之前有一个范例,相同的结果可以用两种作法来实践 [GridView] 资料系结表达 ...
- [C# 基础知识系列]专题五:当点击按钮时触发Click事件背后发生的事情 (转载)
当我们在点击窗口中的Button控件VS会帮我们自动生成一些代码,我们只需要在Click方法中写一些自己的代码就可以实现触发Click事件后我们Click方法中代码就会执行,然而我一直有一个疑问的—— ...
- GridView控件RowDataBound事件中获取列字段值的几种途径 !!!
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == ...
随机推荐
- Javascript 函数传参问题
属于传值,不能改变参数的属性 example 1 function Myvalue(){ var arry = 5; return arry ; } document.getElementById( ...
- 抽象类(abstract class)
package com.bjsxt.oop.abstractClass; //抽象类 public abstract class Animal { //因为父类的方法总是被重写 那就没写的必要了 但是 ...
- JSP复习(part 2 )
3.4.2 访问(获取)请求参数 1.方法 String 字符串变量 =request.getParameter("客户端提供参数的name属性名"): 2.传参数的三种形式 (1 ...
- Typora快捷键的使用
无序列表:输入-之后输入空格 有序列表:输入数字+“.”之后输入空格 任务列表:-[空格]空格 文字 标题:ctrl+数字 表格:ctrl+t 生成目录:[TOC]按回车 选中一整行:ctrl+l 选 ...
- Linux 软件 安装到 /usr,/usr/local/ 还是 /opt 目录
Linux 的软件安装目录是也是有讲究的,理解这一点,在对系统管理是有益的 /usr:系统级的目录,可以理解为C:/Windows/,/usr/lib理解为C:/Windows/System32./u ...
- 参数错误导致bug
1.网站参数与数据库参数名字不一致(大小写). 2.参数漏掉一个字母(characterno写成了charaterno).
- ThreadPoolExecutor常识
线程池技术在并发时经常会使用到,java中的线程池的使用是通过调用ThreadPoolExecutor来实现的.ThreadPoolExecutor提供了四个构造函数,最后都会归结于下面这个构造方法: ...
- Ubuntu中解决机箱前置耳机没声音
Ubuntu中解决机箱前置耳机没声音 安装pavucontrol软件: sudo apt-get install pavucontrol 然后直接运行pavucontrol打开软件: 将输出设备设置为 ...
- 安卓机在按HOME键时,UNITY触发的APPLICATION_PAUSE事件
安卓机在按HOME键时,UNITY触发的APPLICATION_PAUSE事件 此时安卓程序会返回,在这一瞬间,程序可以通过SOCKET发送数据包给服务器告知, 经测试在这短暂的时间内,这个数据包能发 ...
- winform弹出文件和目录选择框
目录选择: FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择文件路径&quo ...