Search code examples
asp.netgridviewcell

ASP.NET GridView: How to retrieve decimal value from a cell at RowDataBound?


I have a Temperature column in my GridView and want to retrieve the temperature value in decimal at RowDataBound. How do I do this? Thanks.


Solution

  • Try this:

    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()); 
    }
    
    }
    

    In case it errors out saying "Input String was not in a correct format" then take a look at this document

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