GridView————绑定GridView时(RowDataBound)添加一些样式
来源:互联网 发布:网络渗透入门 编辑:程序博客网 时间:2024/05/17 00:58
/// <summary>
/// 绑定GridView时(RowDataBound)添加一些属性
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//行单元格从0开始数
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "yes=this.style.backgroundColor; this.style.backgroundColor='red'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=yes");
//获取绑定行的book对象
Book book = (Book)e.Row.DataItem;
//给 价格 的单元格添加color颜色
if (book.UnitPrice < 80)
{
e.Row.Cells[8].Attributes.Add("style", "color:green");
// e.Row.Cells[6].Text = "便宜";
}
else if (book.UnitPrice < 200)
{
e.Row.Cells[8].Attributes.Add("style", "color:yellow");
}
else
{
e.Row.Cells[8].Attributes.Add("style", "color:red");
}
this.sumPrice += Convert.ToSByte(book.UnitPrice); //累加价格(方便计算平均价格)
//序号1,2,3......
String num = Convert.ToString(e.Row.RowIndex + 1);
e.Row.Cells[0].Text = num;
//判断内容的字数是否大于20,如果大于,就是只显示20个字符+....
if (book.ContentDescription.Length > 20)
{
e.Row.Cells[5].Text = book.ContentDescription.Substring(0, 20) + "...";
}
//隐藏列
// e.Row.Cells[6].Attributes.Add("style", "display:none"); //隐藏数据列
}
else if (e.Row.RowType == DataControlRowType.Footer) //判断是不是脚注行
{
e.Row.Cells[7].Text = "均价";
float avgPrice = sumPrice / this.gvBook.Rows.Count; //注:Rows不包含标头行和脚注行
String money = String.Format("{0:C2}", avgPrice); //格式化均价(以货币的形式显示)
e.Row.Cells[8].Text = money;
}
}
- GridView————绑定GridView时(RowDataBound)添加一些样式
- DataTable绑定到GridView时,RowDataBound事件
- 《ASP.NET》数据绑定——GridView
- GridView.RowDataBound 事件
- .net GridView.RowDataBound 事件
- GridView的RowDataBound用法
- GridView中的RowDataBound事件
- gridView RowDataBound事件详解
- ASP.NET之Gridview的行绑定事件RowDataBound事件
- Gridview的RowDataBound事件(添加删除提示,改变背景颜色)
- GridView的RowDataBound事件可做的一些事情
- GridView的RowDataBound事件可做的一些事情
- GridView数据绑定——DataAdapter和DataSet使用示例
- ASP.NET——GridView控件绑定数据
- ASP.NET——GridView控件绑定数据
- ASP.NET—001:GridView绑定List、页面返回值
- GridView的RowDataBound事件写法
- Gridview部分方法说明-RowDataBound
- 需求分析的点
- log4cplus 分级显示控制
- IPC——无名管道pipe
- 单代号搭接网络计划
- 天涯花8语录
- GridView————绑定GridView时(RowDataBound)添加一些样式
- Java中文问题之解决方法,比较全
- Download Android 1.5 SDK, Release 3
- velocity应用
- JBPM基础
- 安装Eclipse和Android:Setting up Eclipse and Android
- android基础应用
- 一个真实的项目经历(转摘)
- 从大连回来