Hi,

I have a gridview that I use to display the results from 50 different SQL database queries.

The gridview is populated and built dynamically (Auto-Generate fields) at runtime based on a query that the user selects. When the data is displayed it looks like this:

A B C D E F
299914 599991011 XX41 65564.000 46039.000000 19525.000000
993210 125115507 XX42 1080024.000 1090560.000000 -10536.000000

In the above example I'd like to format Columns C, D and E to show the number without all the decimal points. However not all queries displayed in the gridview are the same, so for a different query I need to format columns's B and D only (See Below):

A B C D
467764 11551.000000 XX43 23982123.000
999950 21111.000000 XX44 752035.000
123450 28444.000000 XX45 65298.555

I think I need to do this in the RowDataBound event and use something similar to below:

e.Row.Cells[x].Text = string.Format("{0:0.0}", e.Row.Cells[x].Text)

However I am unsure how to loop through the rows/cells to find the problem cells/data and then format.

Any help would be greatly appreciated.

Many Thanks
Paul

Loop through the values and you can use

int num=Convert.ToInt32(Convert.ToDecimal(value));

once the number is extracted fill the gridview with this value

Convert.ToString(num);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.