0

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

shweta
  • 319
  • 2
  • 8
  • 21
  • Why don't you compute this value, at source level? Instead of calculating this in the grid, calculate this maybe at database level? – Mez Oct 24 '14 at 11:22
  • actually i want to show them in grid for each record and in grid I have checkbox..so whichever check is true I need to read that value and add and then show final amount in message – shweta Oct 24 '14 at 11:25
  • How about configuring the columns, as visible="False"? At runtime you can still access these values? You can also format them by expressions such as DataFormatString="{0:c}", for money. – Mez Oct 24 '14 at 11:26
  • This should work, tried it in my code and it worked. So are you sure the datakey contains for eg 220.75? Try to put a breakpoint before and after the method runs – Koen Oct 24 '14 at 12:08

1 Answers1

0

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());
Dennis R
  • 3,195
  • 1
  • 19
  • 24