ASP.NET GridView:如何从RowDataBound的单元格中检索十进制值?

时间:2011-06-18 19:02:02

标签: asp.net gridview cell

我的GridView中有一个Temperature列,想要在RowDataBound中检索十进制的温度值。我该怎么做呢?感谢。

1 个答案:

答案 0 :(得分:2)

试试这个:

void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
 {

   if(e.Row.RowType == DataControlRowType.DataRow)
    {
        // say temparature field in column 3

        decimal temp = decimal.Parse(e.Row.Cells[2].Text.ToString()); 
}

}

如果出现“输入字符串格式不正确”的错误,请查看此文档

http://www.codeproject.com/KB/cs/Eduardo_Sierra.aspx