熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

asp.net如何得到GRIDVIEW中某行某列值的方法

2022-06-13   來源: .NET編程 

  根據某列的值改變其樣式最好的方法是在GridView的DataRowBound事件中想辦法在GridView中的行綁定數據後將立即執行 DataRowBound事件DataRowBound事件使用GridViewRowEventargs類作為事件變量通過事件變量你能夠利用 GridViewRowEventArgs屬性操作已經綁定數據的行

復制代碼 代碼如下:
protected void GridView_RowDataBound(object sender GridViewRowEventArgs e)
{
GridViewRow row = eRow;
}

  
Row將返回TableRow類中的一個GridViewRow對象
綁 定的Row有幾種不同的類型例如DataRow EmptyDataRow Footer Header Pager 和 Separator通過GridView的RowType屬性可以得到當前行的行類型RowType是一組DataControlRow枚舉
看下面的代碼示例檢測GridView列出的行是否為一個標准類型的行

復制代碼 代碼如下:
protected void GridView_RowDataBound(object sender GridViewRowEventArgs e)
{
if (eRowRowType == DataControlRowTypeDataRow)
{
//Do something!
}
}

  
可 以使用Row的Cells屬性得到其Cells它將返回一個TableCellCollection對象然後通過 TableCellCollection索引得到特定的CellsTableCellcollection索引將返回一個TabelCell對象對應 於Row中的一個Cell

復制代碼 代碼如下:

  
protected void GridView_RowDataBound(object sender GridViewRowEventArgs e)
{
if (eRowRowType == DataControlRowTypeDataRow)
{
string value = eRowCells[]Text;
}
}


From:http://tw.wingwit.com/Article/program/net/201311/14254.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.