更改DataTable列值 [英] Change DataTable Column Value
本文介绍了更改DataTable列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的DataTable:
I have one DataTable like this:
Attribute Percentage ReferenceAmount TaxAmount
------------ ------------ ---------------- -----------
Sales 5.00 5000 250
VAT 2.00 250 5
Discount 0 0 100
我想绑定这个DataTable与一个GridView。
但在GridView中,我不想显示0.而不是零,我只是想让该单元格为空。如果包含零,我不想显示任何其他东西。
如何在DataTable中替换EmptyString而不是Zero?
I want to Bind this DataTable with one GridView. But in the GridView, I dont want to display 0. Instead of Zero, I just want leave that cell as empty. I dont want to display any other thing if that contains Zero. How to replace EmptyString instead of Zero in the DataTable?
推荐答案
以下GridView DataBound方法将遍历GridView中的每个单元格,并用空字符串替换0 p>
The following GridView DataBound method will loop through every cell in the GridView and replace "0" with an empty string:
protected void GridView1_DataBound(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
for (int i = 0; i < row.Cells.Count - 1; i++)
{
if (row.Cells[i].Text == "0")
{
row.Cells[i].Text = "";
}
}
}
}
这篇关于更改DataTable列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文