0

I'm creating a html table at runtime (no probs there), and I would like to be able to format the content in the cells at runtime by passing in a format string (ie currencies, decimals, decimal places etc)

for example, i want to achieve something like this but to be able to pass in the format of the string with code as a string, ie "{0:c}" or "#,###,###"

ideally to be able to pass it into the ToString() method ( i can't do that but was wondering if there could be a clever way to achieve this?)

tblCell.Text = dt.Rows[i][j].ToString(#.##);
1
  • where does the data for the html table come from? Would GridView or ListView an option? I added an answer to show what I mean. Commented Sep 13, 2011 at 5:36

3 Answers 3

1
tblCell.Text = String.Format("{0:c}", dt.Rows[i][j])

and

tblCell.Text = String.Format("{0:#.##}", dt.Rows[i][j])

should work.

Sign up to request clarification or add additional context in comments.

Comments

0

You can supply format strings to the columns in your GridView by setting the DataFormatString property of the column to something like this: “{0:d}”.

Comments

0

Have a look at: http://www.cheat-sheets.org/saved-copy/msnet-formatting-strings.pdf

I always use this cheat sheet to find out things like these as the number of possibilities is simply to big to remember them all

1 Comment

Links seems to be down. :-(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.