如何在ASP gridview dataformatstring中使用代码后面的变量 [英] How to use variable from code behind in ASP gridview dataformatstring

查看:78
本文介绍了如何在ASP gridview dataformatstring中使用代码后面的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview包含此列

I have a gridview contains this column

<asp:BoundField DataField="Total" HeaderText="<%$Resources:Labels, Total%>" DataFormatString="{0:F3}"/>





我在代码后面有这个变量



and I have this variable in code behind

public static class Features
 {
   public static int Decimals = 1;
 }





我想用变量 Decimals in

DataFormatString="{0:F3}"/>





我的尝试:





What I have tried:

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




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





无效



nothing works

推荐答案

资源:标签,总计%> DataFormatString = < span class =code-string> {0:F3} />
Resources:Labels, Total%>" DataFormatString="{0:F3}"/>





我在代码中有这个变量



and I have this variable in code behind

public static class Features
 {
   public static int Decimals = 1;
 }





我想用变量 Decimals in

DataFormatString="{0:F3}"/>





我的尝试:





What I have tried:

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




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





无效



nothing works


我还没有真正尝试将变量传递给 DataFormatString ,我不确定这是否会起作用。您可能希望在代码后面的代码处理格式。例如,您可以在 DataBound 事件 GridView



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:

//Where ColumnIndex is the column position. Note that index starts at 0
((BoundField)GridView1.Columns[ColumnIndex]).DataFormatString = YourCustomFormatStringVariable;


请转到通过 GridView中的数据格式化 [ ^ ]

并尝试添加列
Please go through Data formatting in GridView[^]
and try adding on column
引用:

HtmlEncode =False

HtmlEncode="False"


这篇关于如何在ASP gridview dataformatstring中使用代码后面的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆