Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview contains this column
C#
<asp:BoundField DataField="Total" HeaderText="<%$Resources:Labels, Total%>" DataFormatString="{0:F3}"/>


and I have this variable in code behind
C#
public static class Features
 {
   public static int Decimals = 1;
 }


I want to replace number "3" with the variable Decimals in
C#
DataFormatString="{0:F3}"/>


What I have tried:

C#
DataFormatString="{0:F<%=Features.Decimals%>}"

C#
DataFormatString='<%="{0:F"+Features.Decimals+"}"%>'


nothing works
Posted
Updated 12-Sep-16 3:30am

I haven't really tried passing a variable to a DataFormatString, and I'm not sure if that is going to work. You may want to handle the formatting at your code behind page instead. For example, you can do something like this at DataBound event of GridView:

C#
//Where ColumnIndex is the column position. Note that index starts at 0
((BoundField)GridView1.Columns[ColumnIndex]).DataFormatString = YourCustomFormatStringVariable;
 
Share this answer
 
Please go through Data formatting in GridView[^]
and try adding on column
Quote:
HtmlEncode="False"
 
Share this answer
 

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