gpt4 book ai didi

c#,设置数据源后设置datagridview列格式

转载 作者:行者123 更新时间:2023-11-30 14:04:41 25 4
gpt4 key购买 nike

我有一个以编程方式填充的数据 GridView ,我想知道如何使其中一列符合指定格式 - “C2”。

这可以在分配数据源后完成吗?

干杯。

最佳答案

       var persons = new[] {new {name = "aaa", salary = 40000}, 
new {name = "aaa", salary = 40000},
new {name = "aaa", salary = 40000},
new {name = "aaa", salary = 40000}};


GridView1.DataSource = persons;
GridView1.AutoGenerateColumns = false;

var NameField = new BoundField();

NameField.HeaderText = "Name";
NameField.DataField = "name";
GridView1.Columns.Add(NameField);

var SalaryField = new BoundField();
SalaryField.HeaderText = "Salary";
SalaryField.DataField = "salary";
SalaryField.DataFormatString = "{0:c2}";
SalaryField.HtmlEncode = false;
GridView1.Columns.Add(SalaryField);


GridView1.DataBind();

关于c#,设置数据源后设置datagridview列格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1344356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com