Click here to Skip to main content
15,906,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datatable which is having 3 rows ,3 columns (min %,max%,default%)
and the values are string type and values are like 2%,5% etc...
now i want to remove percentage(%) in all the values in the the column values should be 2,5 etc...

Please help me regarding the same..

To Sort the Colmns:
dt.DefaultView.Sort="Column Name";

And to add % when you display:
Convert.ToString (row[col])+"%";
Share this answer
siva455 11-May-11 3:21am    
im not concern about sorting asking how can i add % to values so that i need to display as 2%,3%...(as i removed % for sorting purpose and i want to revert it while displaying...)
RAJI @Codeproject 11-May-11 3:28am    
is that helped?
siva455 11-May-11 4:18am    
actually no...bcos i need to add % to values to which i have removed % earlier,not to all the columns...even i need to update the datatable also..
Try this!

foreach (DataRow row in dt.Rows)
             foreach (DataColumn col in dt.Columns){

             string h= Convert.ToString (row[col]);
              row[col]=  h.Replace ("%","");


Share this answer
siva455 11-May-11 3:01am    
thanks for ur reply..even without AcceptChanges() also it"s working...and one more thing actually i want to remove % as i want to sort the when im displaying i want to display values with %...please let me know how can i achieve the same....
Those columns should be numeric to start with. Wherever you are creating the data table (and in the input validator if you expect the user to enter numbers that way), convert to the actual numeric value, and when you display values, apply the appropriate formatter.

If you're using a DataGridView the hooks you want are DataGridView.CellValidating (for input) and DataGridViewColumn.DefaultCellStyle.FormatString (for display).
Share this answer
siva455 12-May-11 0:32am    
no user input here
BobJanova 12-May-11 13:51pm    
Then just set the DataGridViewColumn.DefaultCellStyle.FormatString for the column to format the numbers as percentages.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900