通过e.Row实现GridViewRow访问单元格

开发 后端
本文简单介绍了如何通过e.Row实现GridViewRow访问单元格。

我们需要访问GridViewID.Rows[index]来访问index对应的那一行,GridViewID.Rows[index].Cells[index]来访问某一单元格.然而当RowDataBound事件触发时,GridViewRow却没有添加到Rows集合中, 因此我们不能在RowDataBound事件处理中通过当前GridViewRow实例

取而代之,我们可以通过e.Row来访问。为了高亮某一行我们用下面的代码

  1. e.Row.BackColor = System.Drawing.Color.Yellow;  

我们还可以通过cSSClass取得同样的效果(推荐)   

  1. protected void HighlightCheapProducts_RowDataBound(object sender, GridViewRowEventArgs e)  
  2.  
  3.     {  
  4.  
  5.         // Make sure we are working with a DataRow  
  6.  
  7.         if (e.Row.RowType == DataControlRowType.DataRow)  
  8.  
  9.         {  
  10.  
  11.             // Get the ProductsRow object from the DataItem property...  
  12.  
  13.             Northwind.ProductsRow product = (Northwind.ProductsRow)((System.Data.DataRowView)e.Row.DataItem).Row;  
  14.  
  15.             if (!product.IsUnitPriceNull() && product.UnitPrice <  10m)  
  16.  
  17.             {  
  18.  
  19.                 e.Row.CssClass = "AffordablePriceEmphasis";  
  20.  
  21.             }  
  22.  
  23.         }  
  24.  
  25.     }  
  26.  

所需要的行用高亮黄色显示 

GridViewRow: 所需要的行用高亮黄色显示

【编辑推荐】

  1. ASP.NET 2.0数据教程:SelectMethod属性的使用
  2. ASP.NET 2.0数据教程:在业务逻辑层添加方法
  3. ASP.NET 2.0数据教程:为TableAdapter添加方法
  4. ASP.NET 2.0数据教程:使用一个硬编码参数值
  5. ASP.NET 2.0数据教程:绑定到ObjectDataSource
责任编辑:book05 来源: 博客堂
相关推荐

2009-08-07 17:54:41

C#单元格数据

2021-08-13 11:10:32

OpenPyXLExcelPython

2013-06-20 11:10:24

iOS开发UItableView单元格背景渐变

2015-01-15 16:34:31

iOS源码单元格

2009-07-27 16:46:07

DetailsView

2010-08-11 16:41:30

Flex DataGr

2010-04-27 11:11:06

Oracle修改JTa

2021-09-09 08:58:32

Excel数据处理函数

2010-08-11 16:30:49

Flex DataGr

2020-02-19 14:55:20

开发技能代码

2021-05-10 10:50:53

NginxIPLinux

2020-11-20 10:52:54

Antd表格日程

2009-07-02 14:42:55

ExtJS Grid

2010-08-26 10:42:18

CSStr td

2024-02-26 00:00:01

​win32WindowsCOM

2011-06-15 10:49:26

Qt QTableItem

2011-06-15 12:58:05

Qt QTableWidg

2022-08-01 08:02:25

单元格可视化语法

2009-08-07 17:56:07

DataGrid的样式

2009-12-08 17:00:19

路由器功能
点赞
收藏

51CTO技术栈公众号