展会信息港展会大全

asp.net如何得到GRIDVIEW中某行某列值的方法
来源:互联网   发布日期:2015-10-03 10:47:36   浏览:1619次  

导读:根据某列的值改变其样式最好的方法是在GridView的DataRowBound事件中想办法。在GridView中的行绑定数据后将立即执行 DataRowBound事件。DataRowBound事件使用GridViewRowEventargs类作为事件变量。通过事件变量 ...

根据某列的值改变其样式最好的方法是在GridView的DataRowBound事件中想办法。在GridView中的行绑定数据后将立即执行 DataRowBound事件。DataRowBound事件使用GridViewRowEventargs类作为事件变量。通过事件变量你能够利用 GridViewRowEventArgs属性操作已经绑定数据的行。

复制代码 代码如下:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

GridViewRow row = e.Row;

}

Row将返回TableRow类中的一个GridViewRow对象。

绑 定的Row有几种不同的类型。例如:DataRow, EmptyDataRow, Footer, Header, Pager 和 Separator。通过GridView的RowType属性可以得到当前行的行类型。RowType是一组DataControlRow枚举。

看下面的代码示例,检测GridView列出的行是否为一个标准类型的行。

复制代码 代码如下:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

//Do something!

}

}

可 以使用Row的Cells属性得到其Cells,它将返回一个TableCellCollection对象。然后通过 TableCellCollection索引得到特定的Cells。TableCellcollection索引将返回一个TabelCell对象,对应 于Row中的一个Cell:

复制代码 代码如下:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

string value = e.Row.Cells[0].Text;

}

}

赞助本站

人工智能实验室

相关热词: GRIDVIEW net

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港