shweta
shweta

Reputation: 319

In gridview Datakey field contains double value but retutns only integer part,how to get complete double value

I'm having Gridview in which two columns I want to hide but need to acces their value so I keep them in dataKey

out of these two datakey field one is application fees..which contains values in double format, now I want these values for calculation...so I used following method to get the values from datakey application fee

   double ApplicationFees =  double.Parse(GridApplicationsList.DataKeys[row.RowIndex].Values[1].ToString());

now for eg if my application fees value is 220.75 in gridview but it gives me 220.0 with above code, how do I achive complete double value from datakey

Upvotes: 0

Views: 311

Answers (1)

Dennis R
Dennis R

Reputation: 3237

It might be possible that you are referencing a wrong field from the DataKeyNames collection by saying Values[1].

Since you're storing two columns in the DataKeyNames property, always try referencing them using by it's name rather than by it's index like below. In case if you are adding one more field to the DataKeyNames property in future then you don't have to change the code to update the index position for the keys.

double ApplicationFees =  double.Parse(GridApplicationsList.DataKeys[row.RowIndex].Values["APP_FEES"].ToString());

Upvotes: 0

Related Questions